home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Shareware Plus / Developers / The Gray Council 1.2.1 / source / PowerPlant / GrayCouncilPP.cpp < prev    next >
Encoding:
Text File  |  1996-11-07  |  111.3 KB  |  4,525 lines  |  [TEXT/CWIE]

  1. //
  2. // The Gray Council PowerPlant Adapter
  3. // Copyright ©1996 by Trygve Isaacson. All Rights Reserved.
  4. //
  5. // PowerPlant adapter classes for The Gray Council.
  6. //
  7. // Before using any of the Gray Council source code, read and
  8. // follow the licensing info in the accompanying documentation
  9. // or contact:
  10. //   <trygve@bombaydigital.com>
  11. //   <http://www.bombaydigital.com>
  12. //
  13. // Also check the web site above to make sure you have the latest version!
  14. //
  15. // The Gray Council provides a set of standard C++ classes that implement
  16. // the standard Apple Grayscale Appearance. The core classes do not
  17. // require any other code such as a particular class framework.
  18. //
  19. // This file defines a set of helper classes that derive from standard
  20. // PowerPlant classes, and interface with the core Gray Council code.
  21. // There are also a couple of attachment subclasses for attaching to
  22. // other pane classes to get a white background and 3D frame.
  23. //
  24. // Normally, to use a Gray Council PowerPlant class, you can simply change the
  25. // class ID of the pane in your Constructor window resource to the
  26. // class ID of the appropriate Gray Council PowerPlant adapter class. For
  27. // example, to use the GC pushbutton, create a normal LButton pane,
  28. // and set its class ID to 'GCpb'. Voila. This also works for the LAttachment
  29. // subclasses defined here.
  30. //
  31. // A couple of the classes use the mUserCon field of the subview to specify
  32. // additional information such as icon IDs, string resource IDs, etc.
  33. //
  34. // If the mUserCon usage conflicts with what you are already doing with it,
  35. // you can use the "extended" pane subclasses (those whose class name ends
  36. // in "PPX" instead of "PP"). These classes read their additional info from
  37. // the pane resource stream instead of using mUserCon. In some cases they
  38. // let you specify additional options in the pane resource that you would
  39. // otherwise have to specify programmatically. The supplied resource file
  40. // named GCCustomPanes.rsrc contains the 'CPPb' custom pane types.
  41. // If you put this file in the Constructor app's folder, or keep it open
  42. // whenever your pane resource file is open, or paste the custom pane
  43. // types into your pane resource file, you can use the extended pane classes
  44. // in Constructor.
  45. //
  46. // Each class here that interfaces to a core AGAObject has a public
  47. // member variable called mAGAObject that points to the actual AGAObject
  48. // subclass object. Certain extended object settings (such as mixed-state
  49. // buttons, proportional and live scrolling, etc.) require you to call
  50. // the AGAObject to set it. The member variable is made public to keep
  51. // these PowerPlant classes as lightweight as possible; you make the call,
  52. // rather than using myriad new functions of the PowerPlant AGA subclasses.
  53. //
  54. // Classes defined below:
  55. //    AGAWindowPP -- LWindow subclass that draws a gray background, with the
  56. //        background type depending on the LWindow windAttr_Modal flag.
  57. //    AGAWindowPPX -- AGAWindowPP (LWindow) subclass, that uses extended
  58. //        CPPb data to determine the background type.
  59. //    AGADialogBoxPP -- LDialogBox subclass that draws a gray background, with
  60. //        the background type depending on the WDEF procID and the LWindow
  61. //        windAttr_Modal flag, and replaces the PowerPlant default button outline
  62. //        by altering the style of the default button AGAPushButton object.
  63. //    AGAWindowPPX -- AGADialogBoxPP (LDialogBox) subclass, that uses extended
  64. //        CPPb data to determine the background type.
  65. //    AGAPushButtonPP -- LStdButton subclass for AGAPushButton.
  66. //    AGACheckBoxPP -- LStdCheckBox subclass for AGACheckBox.
  67. //    AGARadioButtonPP -- LStdRadioButton subclass for AGARadioButton.
  68. //    AGAIconPushButtonPP -- AGAPushButtonPP (LStdButton) subclass for
  69. //        AGAIconPushButton.
  70. //    AGAIconPushButtonPPX -- AGAIconPushButtonPP (LStdButton) subclass for
  71. //        AGAIconPushButton, that uses extended CPPb data for the icon ID.
  72. //    AGAIconCheckBoxPP -- AGACheckBoxPP (LStdCheckBox) subclass for
  73. //        AGAIconCheckBox.
  74. //    AGAIconCheckBoxPPX -- AGAIconCheckBoxPP (LStdCheckBox) subclass for
  75. //        AGAIconCheckBox, that uses extended CPPb data for the icon IDs.
  76. //    AGAIconRadioButtonPP -- AGARadioButtonPP (LStdRadioButton) subclass
  77. //        for AGAIconRadioButton.
  78. //    AGAIconRadioButtonPPX -- AGAIconRadioButtonPP (LStdRadioButton) subclass
  79. //        for AGAIconRadioButton, that uses extended CPPb data for the icon IDs.
  80. //    AGAGroupBoxPP -- LGroupBox subclass for AGAGroupBox, with primary group
  81. //        box appearance.
  82. //    AGAGroupBoxPPX -- AGAGroupBoxPP (LGroupBox) subclass for AGAGroupBox,
  83. //        that uses extended CPPb data for the box type and gap pane ID.
  84. //    AGASecondaryGroupBoxPP -- AGAGroupBoxPP (LGroupBox) subclass for
  85. //        AGAGroupBox, with secondary group box appearance.
  86. //    AGAScrollBarPP -- LStdControl subclass for AGAScrollBar.
  87. //    AGAScrollerPP -- LScroller subclass that replaces the normal LStdControl
  88. //        scroll bars with ones of class AGAScrollBarPP, and correctly
  89. //        maintain them during scrolling.
  90. //    AGAActiveScrollerPP -- LActiveScroller replacement; actually an AGAScrollerPP
  91. //        subclass that sets the AGA scroll bars for live scrolling.
  92. //    AGASliderPP -- LControl subclass for AGASlider.
  93. //    AGASliderPPX -- AGASliderPP (LControl) subclass for AGASlider, that
  94. //        uses extended CPPb data for the label strings ID, style, and
  95. //        slider justification.
  96. //    AGALittleArrowsPP -- LControl subclass for AGALittleArrows.
  97. //    AGALittleArrowsPPX -- AGALittleArrowsPP (LControl) subclass for
  98. //        AGALittleArrows, that uses extended CPPb data for the linked
  99. //        numeric LEditField pane ID.
  100. //    AGAPopupMenuPP -- LStdPopupMenu subclass for AGAPopupMenu.
  101. //    AGADisclosureTrianglePP -- LControl subclass for AGADisclosureTriangle.
  102. //    AGAProgressIndicatorPP -- LControl subclass for AGAProgressIndicator.
  103. //    AGAWhiteBackgroundAttachmentPP -- LAttachment subclass that draws a
  104. //        white background for the pane to which it is attached.
  105. //    AGANotchedWhiteBackgroundAttachmentPP -- AGAWhiteBackgroundAttachmentPP (LAttachment)
  106. //        subclass that avoids painting the "notch" at the bottom right.
  107. //    AGABorderFrameAttachmentPP -- LAttachment subclass that draws a
  108. //        "3D" sunken frame around the pane to which it is attached.
  109. //    AGANotchedBorderFrameAttachmentPP -- AGABorderFrameAttachmentPP (LAttachment)
  110. //        subclass that accounts for the "notch" at the bottom right.
  111. //    AGAEditFieldPP -- LEditField subclass that automatically attaches an
  112. //        AGAWhiteBackgroundAttachmentPP and an AGABorderFrameAttachmentPP,
  113. //        and also knows how to draw the frame in disabled gray when disabled.
  114. //    AGATextEditPP -- LTextEdit subclass that automatically attaches an
  115. //        AGAWhiteBackgroundAttachmentPP and an AGABorderFrameAttachmentPP.
  116. //    AGASeparatorPP -- LPane subclass for AGASeparator.
  117. //    AGACaptionPP -- LCaption subclass for AGAStaticText.
  118. //    AGAListBoxPP -- LListBox subclass that automatically attaches an
  119. //        AGAWhiteBackgroundAttachmentPP and an AGABorderFrameAttachmentPP,
  120. //        and also replaces the normal LFocusBox with an AGAFocusBoxPP so
  121. //        that the focus frame appears correct.
  122. //    AGANotchedListBoxPP -- AGAListBoxPP (LListBox) subclass that uses an
  123. //        AGANotchedWhiteBackgroundAttachmentPP instead of an AGAWhiteBackgroundAttachmentPP.
  124. //    AGANotchedFocusListBoxPP -- AGANotchedListBoxPP (LListBox) subclass that
  125. //        uses both an AGANotchedWhiteBackgroundAttachmentPP instead of an
  126. //        AGAWhiteBackgroundAttachmentPP, and an AGANotchedFocusBoxPP instead of
  127. //        an AGAFocusBoxPP.
  128. //    AGAFocusBoxPP -- LFocusBox subclass used by AGAListBox to draw the
  129. //        list box focus frame.
  130. //    AGANotchedFocusBoxPP -- AGAFocusBoxPP (LFocusBox) subclass that draws the
  131. //        focus box fitted to the "notch" in the bottom right corner.
  132. //    AGAPanelEnclosurePP -- LView+LCommander subclass, used by AGATabPanelPP to
  133. //        handle target activation/deactivation between targets inside panels.
  134. //    AGATabPanelPP -- LView subclass for AGATabPanel, set for standard large
  135. //        tab format using the system font.
  136. //    AGATabPanelPPX -- AGATabPanelPP (LView) subclass for AGATabPanel, that
  137. //        uses extended CPPb data for the label strings ID, and text traits ID.
  138. //        The font size of the text traits resource determines whether the tabs
  139. //        are small or large format.
  140. //    AGASmallTabPanelPP -- AGATabPanelPP (LView) subclass for AGATabPanel, set
  141. //        for standard small tab format using Geneva 10 bold.
  142. //
  143.  
  144. #include "GrayCouncilPP.h"
  145.  
  146. #include <UDrawingUtils.h>
  147. #include <UReanimator.h>
  148.  
  149. // There are 6 places in this file that use run-time type
  150. // information (RTTI). This requires turning on the RTTI switch
  151. // in the CodeWarrior C/C++ Language preferences panel. If for
  152. // some reason you can't do this, simply #define NO_RTTI here
  153. // and the RTTI-dependent code will be skipped. But if you do
  154. // this, check the comments below where the RTTI usage is so
  155. // that you don't violate the constraints that the RTTI usage
  156. // was checking for.
  157.  
  158. #ifndef NO_RTTI
  159. #include <typeinfo.h>
  160. #endif // NO_RTTI
  161.  
  162. #pragma segment GrayCouncilPP1
  163.  
  164. // The URegistrar::RegisterClass calls are making my eyes hurt.
  165. // Define a macro to do it instead. We take advantage of the fact that
  166. // we use the names class_ID and CreateStream in all of our classes.
  167. #define GCPP_REGISTER_CLASS(classname) URegistrar::RegisterClass(classname::class_ID, (ClassCreatorFunc) classname::CreateStream)
  168.  
  169. OSErr InitGrayCouncilPP()
  170.     {
  171.     //
  172.     // Register our dynamically instantiated pane & attachment subclasses.
  173.     //
  174.  
  175.     GCPP_REGISTER_CLASS(AGAWhiteBackgroundAttachmentPP);
  176.     GCPP_REGISTER_CLASS(AGANotchedWhiteBackgroundAttachmentPP);
  177.     GCPP_REGISTER_CLASS(AGABorderFrameAttachmentPP);
  178.     GCPP_REGISTER_CLASS(AGANotchedBorderFrameAttachmentPP);
  179.     GCPP_REGISTER_CLASS(AGAWindowPP);
  180.     GCPP_REGISTER_CLASS(AGADialogBoxPP);
  181.     GCPP_REGISTER_CLASS(AGAPushButtonPP);
  182.     GCPP_REGISTER_CLASS(AGACheckBoxPP);
  183.     GCPP_REGISTER_CLASS(AGARadioButtonPP);
  184.     GCPP_REGISTER_CLASS(AGAIconPushButtonPP);
  185.     GCPP_REGISTER_CLASS(AGAIconPushButtonPPX);
  186.     GCPP_REGISTER_CLASS(AGAIconCheckBoxPP);
  187.     GCPP_REGISTER_CLASS(AGAIconCheckBoxPPX);
  188.     GCPP_REGISTER_CLASS(AGAIconRadioButtonPP);
  189.     GCPP_REGISTER_CLASS(AGAIconRadioButtonPPX);
  190.     GCPP_REGISTER_CLASS(AGAScrollBarPP);
  191.     GCPP_REGISTER_CLASS(AGAScrollerPP);
  192.     GCPP_REGISTER_CLASS(AGAActiveScrollerPP);
  193.     GCPP_REGISTER_CLASS(AGAGroupBoxPP);
  194.     GCPP_REGISTER_CLASS(AGAGroupBoxPPX);
  195.     GCPP_REGISTER_CLASS(AGASecondaryGroupBoxPP);
  196.     GCPP_REGISTER_CLASS(AGASliderPP);
  197.     GCPP_REGISTER_CLASS(AGASliderPPX);
  198.     GCPP_REGISTER_CLASS(AGALittleArrowsPP);
  199.     GCPP_REGISTER_CLASS(AGALittleArrowsPPX);
  200.     GCPP_REGISTER_CLASS(AGAPopupMenuPP);
  201.     GCPP_REGISTER_CLASS(AGADisclosureTrianglePP);
  202.     GCPP_REGISTER_CLASS(AGAProgressIndicatorPP);
  203.     GCPP_REGISTER_CLASS(AGAEditFieldPP);
  204.     GCPP_REGISTER_CLASS(AGATextEditPP);
  205.     GCPP_REGISTER_CLASS(AGASeparatorPP);
  206.     GCPP_REGISTER_CLASS(AGAListBoxPP);
  207.     GCPP_REGISTER_CLASS(AGANotchedListBoxPP);
  208.     GCPP_REGISTER_CLASS(AGANotchedFocusListBoxPP);
  209.     GCPP_REGISTER_CLASS(AGAFocusBoxPP);
  210.     GCPP_REGISTER_CLASS(AGANotchedFocusBoxPP);
  211.     GCPP_REGISTER_CLASS(AGACaptionPP);
  212.     GCPP_REGISTER_CLASS(AGAPanelEnclosurePP);
  213.     GCPP_REGISTER_CLASS(AGATabPanelPP);
  214.     GCPP_REGISTER_CLASS(AGATabPanelPPX);
  215.     GCPP_REGISTER_CLASS(AGASmallTabPanelPP);
  216.  
  217.     // Do Core Gray Council initialization.
  218.     return InitGrayCouncil();
  219.     }
  220.  
  221. static SInt32 MinSInt32(SInt32 a, SInt32 b) { return (a < b) ? a : b; }
  222. static SInt32 MaxSInt32(SInt32 a, SInt32 b) { return (a > b) ? a : b; }
  223.  
  224. static SInt32 GetTextTraitsJustification(ResIDT inTextTraitsID)
  225.     {
  226.     TextTraitsH    aTTHandle = UTextTraits::LoadTextTraits(inTextTraitsID);
  227.     
  228.     if (aTTHandle == NULL)
  229.         return teFlushDefault;
  230.     else
  231.         return (**aTTHandle).justification;
  232.     }
  233.  
  234. static void ResetAGAObjectFrame(LPane* itsPane, AGAObject* theAGAObject)
  235.     {
  236.     // Change the AGA object's bounds to match the pane's new
  237.     // bounds. Check for the AGA not yet having been created,
  238.     // and tell it not to redraw (it will get a draw message
  239.     // with the update event).
  240.  
  241.     if (theAGAObject != NULL)
  242.         {
  243.         Rect    bounds;
  244.         
  245.         (void) itsPane->CalcLocalFrameRect(bounds);
  246.  
  247.         theAGAObject->SetObjectBounds(&bounds, AGAObject::kDontRedraw);
  248.         }
  249.     }
  250.  
  251. //
  252. // This is the AGATextStyle constructor that is only available
  253. // when compiling with __PowerPlant__ defined. It is conditionally
  254. // declared in GrayCouncil.h, but implemented here since the symbol
  255. // won't be defined when GrayCouncil.cpp is compiled unless precompiled
  256. // headers are used, which is a bad assumption.
  257. //
  258.  
  259. AGATextStyle::AGATextStyle(ResIDT inTextTraitsID)
  260.     {
  261.     // Construct from a PowerPlant Text Traits resource.
  262.  
  263.     TextTraitsH aTTHandle = UTextTraits::LoadTextTraits(inTextTraitsID);
  264.     
  265.     if (aTTHandle == NULL)    // likely, cos there is no "0" Txtr resource
  266.         {
  267.         mFontNum = systemFont;    // typically Chicago
  268.         mFontSize = 0;            // application size, typically 12-point
  269.         mFontStyle = normal;
  270.         }
  271.     else
  272.         {
  273.         mFontNum = (**aTTHandle).fontNumber;
  274.         mFontSize = (**aTTHandle).size;
  275.         mFontStyle = (**aTTHandle).style;
  276.         
  277.         if (mFontNum == UTextTraits::fontNumber_Unknown) // means use supplied font name
  278.             {
  279.             Str255    fontName;
  280.             
  281.             AGA_PLstrcpy(fontName, (**aTTHandle).fontName);
  282.             ::GetFNum(fontName, &mFontNum);
  283.             }
  284.         }
  285.     }
  286.  
  287. //
  288. // AGAWindowPP ----------------------------------------------------
  289. //
  290.  
  291. #undef Inherited
  292. #define Inherited LWindow
  293.  
  294. AGAWindowPP* AGAWindowPP::CreateStream(LStream* inStream)
  295.     {
  296.     return new AGAWindowPP(inStream);
  297.     }
  298.  
  299. AGAWindowPP::AGAWindowPP(LStream* inStream)
  300. : Inherited(inStream)
  301.     {
  302.     if (this->HasAttribute(windAttr_Modal))
  303.         mBackgroundKind = kRaisedModalBackground;
  304.     else
  305.         mBackgroundKind = kRaisedModelessBackground;
  306.     }
  307.  
  308. AGAWindowPP::~AGAWindowPP()
  309.     {
  310.     }
  311.  
  312. void AGAWindowPP::FinishCreate()
  313.     {
  314.     // Make sure that the gray background color is installed
  315.     // prior to subpanes having their FinishCreateSelf method
  316.     // called.
  317.  
  318.     this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
  319.     this->ApplyForeAndBackColors();
  320.     
  321.     Inherited::FinishCreate();
  322.     }
  323.  
  324. void AGAWindowPP::FinishCreateSelf()
  325.     {
  326.     // Let LWindow do its normal stuff first.
  327.     
  328.     Inherited::FinishCreateSelf();
  329.     
  330.     // Either modify the WCTB background color, or
  331.     // just set QD background color.
  332.  
  333.     if (mBackgroundKind == kFlatWindowBackground)
  334.         ThrowIfOSErr_(AGAInstallGrayWCTB(mMacWindowP));
  335.     else if (mBackgroundKind != kNoBackgroundPaint)
  336.         this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
  337.     }
  338.  
  339. void AGAWindowPP::DrawSelf()
  340.     {
  341.     if (mBackgroundKind == kNoBackgroundPaint)
  342.         Inherited::DrawSelf();
  343.     else
  344.         {
  345.         // Change normal DrawSelf by drawing our background.
  346.  
  347.         if (this->HasAttribute(windAttr_EraseOnUpdate))
  348.             this->DrawBackground(&mMacWindowP->portRect, true, mActive == triState_On);
  349.         
  350.         this->DrawSizeBox();
  351.         }
  352.     }
  353.  
  354. void AGAWindowPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  355.     {
  356.     // For raised backgrounds,
  357.     // if the window size is changing in either direction, we need
  358.     // to invalidate the right/bottom edge pixels that will
  359.     // need to turn gray when the window is expanded, either before
  360.     // or after the resize.
  361.     
  362.     this->InvalidateEdges(true, inWidthDelta, inHeightDelta);
  363.  
  364.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  365.     
  366.     this->InvalidateEdges(false, inWidthDelta, inHeightDelta);
  367.     }
  368.  
  369. void AGAWindowPP::ActivateSelf()
  370.     {
  371.     // Redraw just the edge pixels that change based on active state.
  372.  
  373.     this->FocusDraw();
  374.     this->DrawBackground(&mMacWindowP->portRect, false, true);
  375.     
  376.     Inherited::ActivateSelf();
  377.     }
  378.  
  379. void AGAWindowPP::DeactivateSelf()
  380.     {
  381.     // Redraw just the edge pixels that change based on active state.
  382.  
  383.     this->FocusDraw();
  384.     this->DrawBackground(&mMacWindowP->portRect, false, false);
  385.     
  386.     Inherited::DeactivateSelf();
  387.     }
  388.  
  389. void AGAWindowPP::DrawBackground(const Rect* area, Boolean fill, Boolean active)
  390.     {
  391.     if (mBackgroundKind != kNoBackgroundPaint)
  392.         AGABackgroundPaint(area, fill, mBackgroundKind, active, this->HasAttribute(windAttr_SizeBox));
  393.     }
  394.  
  395. void AGAWindowPP::InvalidateEdges(Boolean before, Int16 inWidthDelta, Int16 inHeightDelta)
  396.     {
  397.     if ((mBackgroundKind == kRaisedModelessBackground) ||
  398.         (mBackgroundKind == kRaisedModalBackground))
  399.         {
  400.         // Invalidate the extra "edge" pixels that need to be redrawn
  401.         // when the window is resized.
  402.  
  403.         Rect    bounds;
  404.         Rect    rectToInvalidate;
  405.         
  406.         this->CalcPortFrameRect(bounds);
  407.  
  408.         if (((inWidthDelta > 0) && before) ||
  409.             ((inWidthDelta < 0) && ! before))
  410.             {
  411.             rectToInvalidate = bounds;
  412.             rectToInvalidate.left = rectToInvalidate.right - 1;
  413.             this->InvalPortRect(&rectToInvalidate);
  414.             }
  415.         
  416.         if (((inHeightDelta > 0) && before) ||
  417.             ((inHeightDelta < 0) && ! before))
  418.             {
  419.             rectToInvalidate = bounds;
  420.             rectToInvalidate.top = rectToInvalidate.bottom - 1;
  421.             this->InvalPortRect(&rectToInvalidate);
  422.             }
  423.         
  424.         if (this->HasAttribute(windAttr_EraseOnUpdate))
  425.             {
  426.             rectToInvalidate = bounds;
  427.             rectToInvalidate.left = rectToInvalidate.right - 16;
  428.             rectToInvalidate.top = rectToInvalidate.bottom - 16;
  429.             this->InvalPortRect(&rectToInvalidate);
  430.             }
  431.         }
  432.     }
  433.  
  434. //
  435. // AGAWindowPPX ----------------------------------------------------
  436. //
  437.  
  438. #undef Inherited
  439. #define Inherited AGAWindowPP
  440.  
  441. AGAWindowPPX* AGAWindowPPX::CreateStream(LStream* inStream)
  442.     {
  443.     return new AGAWindowPPX(inStream);
  444.     }
  445.  
  446. AGAWindowPPX::AGAWindowPPX(LStream* inStream)
  447. : Inherited(inStream)
  448.     {
  449.     inStream->ReadData(&mBackgroundKind, sizeof(mBackgroundKind));
  450.     }
  451.  
  452. AGAWindowPPX::~AGAWindowPPX()
  453.     {
  454.     }
  455.  
  456. //
  457. // AGADialogBoxPP ----------------------------------------------------
  458. //
  459.  
  460. #undef Inherited
  461. #define Inherited LDialogBox
  462.  
  463. AGADialogBoxPP* AGADialogBoxPP::CreateStream(LStream* inStream)
  464.     {
  465.     return new AGADialogBoxPP(inStream);
  466.     }
  467.  
  468. AGADialogBoxPP::AGADialogBoxPP(LStream* inStream)
  469. : Inherited(inStream)
  470.     {
  471.     mDeleteDefaultOutline = false;
  472.     mBackgroundKind = kFlatWindowBackground;
  473.     
  474.     //
  475.     // We need to determine the window proc ID in order to really
  476.     // decide what kind of background to do. So, let's find out
  477.     // the same way that PowerPlant does. The SWindowInfo back
  478.     // there in the stream contains a WINDid field, which is the
  479.     // id of a 'WIND' resource. The 'WIND' resource has the proc ID.
  480.     //
  481.     
  482.     SInt32    originalMarker = inStream->GetMarker();
  483.     
  484.     // Undo the LDialogBox stream read.
  485.     inStream->SetMarker(-sizeof(PaneIDT), streamFrom_Marker);
  486.     inStream->SetMarker(-sizeof(PaneIDT), streamFrom_Marker);
  487.     
  488.     // Undo the LWindow stream read.
  489.     inStream->SetMarker(-sizeof(SWindowInfo), streamFrom_Marker);
  490.     
  491.     // Re-read the SWindowInfo.
  492.     SWindowInfo    windowInfo;
  493.     inStream->ReadData(&windowInfo, sizeof(SWindowInfo));
  494.     
  495.     // Peek into the 'WIND' resource, as done by LWindow::MakeMacWindow.
  496.     SWINDResourceH    theWIND = (SWINDResourceH) ::GetResource('WIND', windowInfo.WINDid);
  497.     SInt16            procID = (**theWIND).procID;
  498.     ::ReleaseResource((Handle) theWIND);
  499.     
  500.     // Restore the stream marker.
  501.     inStream->SetMarker(originalMarker, streamFrom_Start);
  502.     
  503.     // Now determine the background kind based on the procID.
  504.     
  505.     if ((procID == dBoxProc) || (procID == movableDBoxProc))
  506.         mBackgroundKind = kFlatWindowBackground;
  507.     else if (this->HasAttribute(windAttr_Modal))
  508.         mBackgroundKind = kRaisedModalBackground;
  509.     else
  510.         mBackgroundKind = kRaisedModelessBackground;
  511.     }
  512.  
  513. AGADialogBoxPP::~AGADialogBoxPP()
  514.     {
  515.     }
  516.  
  517. void AGADialogBoxPP::FinishCreate()
  518.     {
  519.     // Make sure that the gray background color is installed
  520.     // prior to subpanes having their FinishCreateSelf method
  521.     // called.
  522.  
  523.     this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
  524.     this->ApplyForeAndBackColors();
  525.     
  526.     Inherited::FinishCreate();
  527.     }
  528.  
  529. void AGADialogBoxPP::FinishCreateSelf()
  530.     {
  531.     // Let LDialogBox do its normal stuff first.
  532.     
  533.     Inherited::FinishCreateSelf();
  534.     
  535.     // Either modify the WCTB background color, or
  536.     // just set QD background color.
  537.  
  538.     if (mBackgroundKind == kFlatWindowBackground)
  539.         ThrowIfOSErr_(AGAInstallGrayWCTB(mMacWindowP));
  540.     else if (mBackgroundKind != kNoBackgroundPaint)
  541.         this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
  542.     
  543.     //
  544.     // Now we remove its LDefaultOutline and set the
  545.     // default our way.
  546.     //
  547.     
  548.     if (mDefaultOutline != NULL)
  549.         {
  550.         delete mDefaultOutline;
  551.         mDefaultOutline = NULL;
  552.         }
  553.  
  554.     this->SetDefaultButton(mDefaultButtonID);
  555.     }
  556.  
  557. void AGADialogBoxPP::SetDefaultButton(PaneIDT inButtonID)
  558.     {
  559.     // If you bypass the RTTI here, you must ensure that the
  560.     // panes represented by the mDefaultButtonID and the
  561.     // inButtonID are a subclass of AGAPushButtonPP.
  562.  
  563.     AGAPushButtonPP*    oldDefaultButton = NULL;
  564.     AGAPushButtonPP*    newDefaultButton = NULL;
  565.     LPane*                oldDefaultPane = this->FindPaneByID(mDefaultButtonID);
  566.     LPane*                newDefaultPane = this->FindPaneByID(inButtonID);
  567.  
  568. #ifndef NO_RTTI
  569.  
  570.     if (oldDefaultPane != NULL)
  571.         oldDefaultButton = dynamic_cast<AGAPushButtonPP*>(oldDefaultPane);
  572.  
  573.     if (newDefaultPane != NULL)
  574.         newDefaultButton = dynamic_cast<AGAPushButtonPP*>(newDefaultPane);
  575.  
  576. #else // NO_RTTI
  577.  
  578.     oldDefaultButton = (AGAPushButtonPP*) oldDefaultPane;
  579.     newDefaultButton = (AGAPushButtonPP*) newDefaultPane;
  580.  
  581. #endif // NO_RTTI
  582.  
  583.     mDefaultButtonID = inButtonID;
  584.     
  585.     if (oldDefaultButton != NULL)
  586.         {
  587.         if (oldDefaultButton->mAGAObject->IsDefault())
  588.             {
  589.             // Tell the old default button that it is no longer
  590.             // the default. This means insetting its frame.
  591.  
  592.             oldDefaultButton->MoveBy(3, 3, true);
  593.             oldDefaultButton->ResizeFrameBy(-6, -6, true);
  594.             oldDefaultButton->mAGAObject->SetDefault(AGAObject::kIsNotDefault, AGAObject::kFrameInside);
  595.             oldDefaultButton->Refresh();
  596.             }
  597.         }
  598.     else if (mDefaultOutline != nil)
  599.         {
  600.         // Not an AGA object. Do it the LDialogBox way...
  601.  
  602.         mDefaultOutline->Refresh();
  603.         delete mDefaultOutline;
  604.         mDefaultOutline = NULL;
  605.         }
  606.     
  607.     if (newDefaultButton != NULL)
  608.         {
  609.         if (! newDefaultButton->mAGAObject->IsDefault())
  610.             {
  611.             // Tell the new default button that it has become
  612.             // the default. This means outsetting its frame.
  613.  
  614.             newDefaultButton->MoveBy(-3, -3, false);
  615.             newDefaultButton->ResizeFrameBy(6, 6, false);
  616.             newDefaultButton->mAGAObject->SetDefault(AGAObject::kIsDefault, AGAObject::kFrameInside);
  617.             newDefaultButton->Refresh();
  618.             }
  619.         }
  620.     else if (newDefaultPane != NULL)
  621.         {
  622.         // Not an AGA object. Do it the LDialogBox way...
  623.  
  624.         ((LControl*) newDefaultPane)->AddListener(this);
  625.         mDefaultOutline = new LDefaultOutline(newDefaultPane);
  626.         mDefaultOutline->Refresh();
  627.         }
  628.     }
  629.  
  630. void AGADialogBoxPP::DrawSelf()
  631.     {
  632.     if (mBackgroundKind == kNoBackgroundPaint)
  633.         Inherited::DrawSelf();
  634.     else
  635.         {
  636.         // Change normal DrawSelf by drawing our background.
  637.  
  638.         if (this->HasAttribute(windAttr_EraseOnUpdate))
  639.             this->DrawBackground(&mMacWindowP->portRect, true, mActive == triState_On);
  640.         
  641.         this->DrawSizeBox();
  642.         }
  643.     }
  644.  
  645. void AGADialogBoxPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  646.     {
  647.     // For raised backgrounds,
  648.     // if the window size is changing in either direction, we need
  649.     // to invalidate the right/bottom edge pixels that will
  650.     // need to turn gray when the window is expanded, either before
  651.     // or after the resize.
  652.     
  653.     this->InvalidateEdges(true, inWidthDelta, inHeightDelta);
  654.  
  655.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  656.     
  657.     this->InvalidateEdges(false, inWidthDelta, inHeightDelta);
  658.     }
  659.  
  660. void AGADialogBoxPP::ActivateSelf()
  661.     {
  662.     // Redraw just the edge pixels that change based on active state.
  663.  
  664.     this->FocusDraw();
  665.     this->DrawBackground(&mMacWindowP->portRect, false, true);
  666.     
  667.     Inherited::ActivateSelf();
  668.     }
  669.  
  670. void AGADialogBoxPP::DeactivateSelf()
  671.     {
  672.     // Redraw just the edge pixels that change based on active state.
  673.  
  674.     this->FocusDraw();
  675.     this->DrawBackground(&mMacWindowP->portRect, false, false);
  676.     
  677.     Inherited::DeactivateSelf();
  678.     }
  679.  
  680. void AGADialogBoxPP::DrawBackground(const Rect* area, Boolean fill, Boolean active)
  681.     {
  682.     if (mBackgroundKind != kNoBackgroundPaint)
  683.         AGABackgroundPaint(area, fill, mBackgroundKind, active, this->HasAttribute(windAttr_SizeBox));
  684.     }
  685.  
  686. void AGADialogBoxPP::InvalidateEdges(Boolean before, Int16 inWidthDelta, Int16 inHeightDelta)
  687.     {
  688.     if ((mBackgroundKind == kRaisedModelessBackground) ||
  689.         (mBackgroundKind == kRaisedModalBackground))
  690.         {
  691.         // Invalidate the extra "edge" pixels that need to be redrawn
  692.         // when the window is resized.
  693.  
  694.         Rect    bounds;
  695.         Rect    rectToInvalidate;
  696.         
  697.         this->CalcPortFrameRect(bounds);
  698.  
  699.         if (((inWidthDelta > 0) && before) ||
  700.             ((inWidthDelta < 0) && ! before))
  701.             {
  702.             rectToInvalidate = bounds;
  703.             rectToInvalidate.left = rectToInvalidate.right - 1;
  704.             this->InvalPortRect(&rectToInvalidate);
  705.             }
  706.         
  707.         if (((inHeightDelta > 0) && before) ||
  708.             ((inHeightDelta < 0) && ! before))
  709.             {
  710.             rectToInvalidate = bounds;
  711.             rectToInvalidate.top = rectToInvalidate.bottom - 1;
  712.             this->InvalPortRect(&rectToInvalidate);
  713.             }
  714.         
  715.         if (this->HasAttribute(windAttr_EraseOnUpdate))
  716.             {
  717.             rectToInvalidate = bounds;
  718.             rectToInvalidate.left = rectToInvalidate.right - 16;
  719.             rectToInvalidate.top = rectToInvalidate.bottom - 16;
  720.             this->InvalPortRect(&rectToInvalidate);
  721.             }
  722.         }
  723.     }
  724.  
  725. //
  726. // AGADialogBoxPPX ----------------------------------------------------
  727. //
  728.  
  729. #undef Inherited
  730. #define Inherited AGADialogBoxPP
  731.  
  732. AGADialogBoxPPX* AGADialogBoxPPX::CreateStream(LStream* inStream)
  733.     {
  734.     return new AGADialogBoxPPX(inStream);
  735.     }
  736.  
  737. AGADialogBoxPPX::AGADialogBoxPPX(LStream* inStream)
  738. : Inherited(inStream)
  739.     {
  740.     inStream->ReadData(&mBackgroundKind, sizeof(mBackgroundKind));
  741.     }
  742.  
  743. AGADialogBoxPPX::~AGADialogBoxPPX()
  744.     {
  745.     }
  746.  
  747. //
  748. // AGAPushButtonPP ----------------------------------------------------
  749. //
  750.  
  751. #undef Inherited
  752. #define Inherited LStdButton
  753.  
  754. AGAPushButtonPP* AGAPushButtonPP::CreateStream(LStream* inStream)
  755.     {
  756.     return new AGAPushButtonPP(inStream);
  757.     }
  758.  
  759. AGAPushButtonPP::AGAPushButtonPP()
  760.     {
  761.     mAGAObject = NULL;
  762.     }
  763.  
  764. AGAPushButtonPP::AGAPushButtonPP(LStream* inStream)
  765. : Inherited(inStream)
  766.     {
  767.     mAGAObject = NULL;
  768.     }
  769.  
  770. AGAPushButtonPP::~AGAPushButtonPP()
  771.     {
  772.     // Delete AGA object if we successfully allocated it.
  773.  
  774.     if (mAGAObject != NULL)
  775.         delete mAGAObject;
  776.     }
  777.  
  778. void AGAPushButtonPP::SetDescriptor(ConstStringPtr inDescriptor)
  779.     {
  780.     Inherited::SetDescriptor(inDescriptor);
  781.     
  782.     // Install the new text in the AGA object. Don't tell it
  783.     // to redraw; the redraw comes from the caller.
  784.  
  785.     Str255    newText;
  786.     this->GetDescriptor(newText);
  787.     mAGAObject->SetTitle(newText, AGAObject::kDontRedraw);
  788.     }
  789.  
  790. void AGAPushButtonPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  791.     {
  792.     // Let the PowerPlant and AGA objects update their bounds.
  793.  
  794.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  795.     
  796.     ResetAGAObjectFrame(this, mAGAObject);
  797.     }
  798.  
  799. void AGAPushButtonPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  800.     {
  801.     // Let the PowerPlant and AGA objects update their bounds.
  802.  
  803.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  804.     
  805.     ResetAGAObjectFrame(this, mAGAObject);
  806.     }
  807.  
  808. void AGAPushButtonPP::FinishCreateSelf()
  809.     {
  810.     // Create and set up the AGAObject.
  811.  
  812.     this->HideSelf();    // make sure the Control Manager object is not drawn
  813.     
  814.     this->CreateAGAObject();
  815.     }
  816.  
  817. void AGAPushButtonPP::DrawSelf()
  818.     {
  819.     // Let the AGAObject draw itself.
  820.  
  821.     if (mAGAObject != NULL)
  822.         mAGAObject->DrawObject();
  823.     }
  824.  
  825. void AGAPushButtonPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  826.     {
  827.     // Let the AGAObject track the mouse.
  828.  
  829.     if (mAGAObject != NULL)
  830.         {
  831.         this->FocusDraw();
  832.         
  833.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  834.             this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
  835.         }
  836.     }
  837.  
  838. void AGAPushButtonPP::HotSpotAction(SInt16 /*inHotSpot*/, Boolean inCurrInside, Boolean /*inPrevInside*/)
  839.     {
  840.     // Draw the button based on the new press state.
  841.  
  842.     if (mAGAObject != NULL)
  843.         {
  844.         this->FocusDraw();
  845.         mAGAObject->DrawButton(inCurrInside);
  846.         }
  847.     }
  848.  
  849. void AGAPushButtonPP::EnableSelf()
  850.     {
  851.     // Let the AGAObject enable itself.
  852.  
  853.     if (mAGAObject != NULL)
  854.         {
  855.         this->FocusDraw();
  856.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  857.         }
  858.     }
  859.  
  860. void AGAPushButtonPP::DisableSelf()
  861.     {
  862.     // Let the AGAObject disable itself.
  863.  
  864.     if (mAGAObject != NULL)
  865.         {
  866.         this->FocusDraw();
  867.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  868.         }
  869.     }
  870.  
  871. void AGAPushButtonPP::ShowSelf()
  872.     {
  873.     // Suppress showing the Control Manager control.
  874.     }
  875.  
  876. void AGAPushButtonPP::CreateAGAObject()
  877.     {
  878.     // Instantiate the particular AGAObject subclass.
  879.  
  880.     Rect    bounds;
  881.     Str255    title;
  882.     
  883.     (void) this->CalcLocalFrameRect(bounds);
  884.     ::GetControlTitle(mMacControlH, title);
  885.  
  886.     ThrowIfNil_(mAGAObject = new AGAPushButton(&bounds, AGATextStyle(mTextTraitsID), title));
  887.  
  888.     if (mEnabled == triState_Off)
  889.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  890.     }
  891.  
  892. //
  893. // AGACheckBoxPP ----------------------------------------------------
  894. //
  895.  
  896. #undef Inherited
  897. #define Inherited LStdCheckBox
  898.  
  899. AGACheckBoxPP* AGACheckBoxPP::CreateStream(LStream* inStream)
  900.     {
  901.     return new AGACheckBoxPP(inStream);
  902.     }
  903.  
  904. AGACheckBoxPP::AGACheckBoxPP()
  905.     {
  906.     mAGAObject = NULL;
  907.     mMaxValue = 2;    // otherwise mixed-state SetValue messages will constrain to 1
  908.     }
  909.  
  910. AGACheckBoxPP::AGACheckBoxPP(LStream* inStream)
  911. : Inherited(inStream)
  912.     {
  913.     mAGAObject = NULL;
  914.     mMaxValue = 2;    // otherwise mixed-state SetValue messages will constrain to 1
  915.     }
  916.  
  917. AGACheckBoxPP::~AGACheckBoxPP()
  918.     {
  919.     // Delete AGA object if we successfully allocated it.
  920.  
  921.     if (mAGAObject != NULL)
  922.         delete mAGAObject;
  923.     }
  924.  
  925. void AGACheckBoxPP::SetDescriptor(ConstStringPtr inDescriptor)
  926.     {
  927.     Inherited::SetDescriptor(inDescriptor);
  928.     
  929.     // Install the new text in the AGA object. Don't tell it
  930.     // to redraw; the redraw comes from the caller.
  931.  
  932.     Str255    newText;
  933.     this->GetDescriptor(newText);
  934.     mAGAObject->SetTitle(newText, AGAObject::kDontRedraw);
  935.     }
  936.  
  937. void AGACheckBoxPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  938.     {
  939.     // Let the PowerPlant and AGA objects update their bounds.
  940.  
  941.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  942.     
  943.     ResetAGAObjectFrame(this, mAGAObject);
  944.     }
  945.  
  946. void AGACheckBoxPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  947.     {
  948.     // Let the PowerPlant and AGA objects update their bounds.
  949.  
  950.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  951.     
  952.     ResetAGAObjectFrame(this, mAGAObject);
  953.     }
  954.  
  955. void AGACheckBoxPP::FinishCreateSelf()
  956.     {
  957.     // Create and set up the AGAObject.
  958.  
  959.     this->HideSelf();    // make sure the Control Manager object is not drawn
  960.     
  961.     this->CreateAGAObject();
  962.     }
  963.  
  964. void AGACheckBoxPP::DrawSelf()
  965.     {
  966.     // Let the AGAObject draw itself.
  967.  
  968.     if (mAGAObject != NULL)
  969.         mAGAObject->DrawObject();
  970.     }
  971.  
  972. void AGACheckBoxPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  973.     {
  974.     // Let the AGAObject track the mouse.
  975.  
  976.     if (mAGAObject != NULL)
  977.         {
  978.         this->FocusDraw();
  979.         
  980.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  981.             this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
  982.         }
  983.     }
  984.  
  985. void AGACheckBoxPP::HotSpotAction(SInt16 /*inHotSpot*/, Boolean inCurrInside, Boolean /*inPrevInside*/)
  986.     {
  987.     // Draw the button based on the new press state.
  988.  
  989.     if (mAGAObject != NULL)
  990.         {
  991.         this->FocusDraw();
  992.         mAGAObject->DrawButton(inCurrInside);
  993.         }
  994.     }
  995.  
  996. void AGACheckBoxPP::EnableSelf()
  997.     {
  998.     // Let the AGAObject enable itself.
  999.  
  1000.     if (mAGAObject != NULL)
  1001.         {
  1002.         this->FocusDraw();
  1003.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  1004.         }
  1005.     }
  1006.  
  1007. void AGACheckBoxPP::DisableSelf()
  1008.     {
  1009.     // Let the AGAObject disable itself.
  1010.  
  1011.     if (mAGAObject != NULL)
  1012.         {
  1013.         this->FocusDraw();
  1014.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  1015.         }
  1016.     }
  1017.  
  1018. void AGACheckBoxPP::ShowSelf()
  1019.     {
  1020.     // Suppress showing the Control Manager control.
  1021.     }
  1022.  
  1023. void AGACheckBoxPP::SetValue(SInt32 inValue)
  1024.     {
  1025.     // Set the actual LControl value and the AGA object value.
  1026.  
  1027.     Inherited::SetValue(inValue);
  1028.  
  1029.     if (mAGAObject != NULL)
  1030.         {
  1031.         this->FocusDraw();
  1032.         mAGAObject->SetValue(mValue, this->IsVisible());
  1033.         }
  1034.     }
  1035.  
  1036. void AGACheckBoxPP::CreateAGAObject()
  1037.     {
  1038.     // Instantiate the particular AGAObject subclass.
  1039.  
  1040.     Rect    bounds;
  1041.     Str255    title;
  1042.     
  1043.     (void) this->CalcLocalFrameRect(bounds);
  1044.     ::GetControlTitle(mMacControlH, title);
  1045.  
  1046.     ThrowIfNil_(mAGAObject = new AGACheckBox(&bounds, AGATextStyle(mTextTraitsID), title, AGAObject::kNoAutomaticState));
  1047.  
  1048.     if (mEnabled == triState_Off)
  1049.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1050.  
  1051.     mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
  1052.     }
  1053.  
  1054. //
  1055. // AGARadioButtonPP ----------------------------------------------------
  1056. //
  1057.  
  1058. #undef Inherited
  1059. #define Inherited LStdRadioButton
  1060.  
  1061. AGARadioButtonPP* AGARadioButtonPP::CreateStream(LStream* inStream)
  1062.     {
  1063.     return new AGARadioButtonPP(inStream);
  1064.     }
  1065.  
  1066. AGARadioButtonPP::AGARadioButtonPP()
  1067.     {
  1068.     mAGAObject = NULL;
  1069.     mMaxValue = 2;    // otherwise mixed-state SetValue messages will constrain to 1
  1070.     }
  1071.  
  1072. AGARadioButtonPP::AGARadioButtonPP(LStream* inStream)
  1073. : Inherited(inStream)
  1074.     {
  1075.     mAGAObject = NULL;
  1076.     mMaxValue = 2;    // otherwise mixed-state SetValue messages will constrain to 1
  1077.     }
  1078.  
  1079. AGARadioButtonPP::~AGARadioButtonPP()
  1080.     {
  1081.     // Delete AGA object if we successfully allocated it.
  1082.  
  1083.     if (mAGAObject != NULL)
  1084.         delete mAGAObject;
  1085.     }
  1086.  
  1087. void AGARadioButtonPP::SetDescriptor(ConstStringPtr inDescriptor)
  1088.     {
  1089.     Inherited::SetDescriptor(inDescriptor);
  1090.     
  1091.     // Install the new text in the AGA object. Don't tell it
  1092.     // to redraw; the redraw comes from the caller.
  1093.  
  1094.     Str255    newText;
  1095.     this->GetDescriptor(newText);
  1096.     mAGAObject->SetTitle(newText, AGAObject::kDontRedraw);
  1097.     }
  1098.  
  1099. void AGARadioButtonPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  1100.     {
  1101.     // Let the PowerPlant and AGA objects update their bounds.
  1102.  
  1103.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  1104.     
  1105.     ResetAGAObjectFrame(this, mAGAObject);
  1106.     }
  1107.  
  1108. void AGARadioButtonPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  1109.     {
  1110.     // Let the PowerPlant and AGA objects update their bounds.
  1111.  
  1112.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  1113.     
  1114.     ResetAGAObjectFrame(this, mAGAObject);
  1115.     }
  1116.  
  1117. void AGARadioButtonPP::FinishCreateSelf()
  1118.     {
  1119.     // Create and set up the AGAObject.
  1120.  
  1121.     this->HideSelf();    // make sure the Control Manager object is not drawn
  1122.     
  1123.     this->CreateAGAObject();
  1124.     }
  1125.  
  1126. void AGARadioButtonPP::DrawSelf()
  1127.     {
  1128.     // Let the AGAObject draw itself.
  1129.  
  1130.     if (mAGAObject != NULL)
  1131.         mAGAObject->DrawObject();
  1132.     }
  1133.  
  1134. void AGARadioButtonPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  1135.     {
  1136.     // Let the AGAObject track the mouse.
  1137.  
  1138.     if (mAGAObject != NULL)
  1139.         {
  1140.         this->FocusDraw();
  1141.         
  1142.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  1143.             this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
  1144.         }
  1145.     }
  1146.  
  1147. void AGARadioButtonPP::HotSpotAction(SInt16 /*inHotSpot*/, Boolean inCurrInside, Boolean /*inPrevInside*/)
  1148.     {
  1149.     // Draw the button based on the new press state.
  1150.  
  1151.     if (mAGAObject != NULL)
  1152.         {
  1153.         this->FocusDraw();
  1154.         mAGAObject->DrawButton(inCurrInside);
  1155.         }
  1156.     }
  1157.  
  1158. void AGARadioButtonPP::EnableSelf()
  1159.     {
  1160.     // Let the AGAObject enable itself.
  1161.  
  1162.     if (mAGAObject != NULL)
  1163.         {
  1164.         this->FocusDraw();
  1165.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  1166.         }
  1167.     }
  1168.  
  1169. void AGARadioButtonPP::DisableSelf()
  1170.     {
  1171.     // Let the AGAObject disable itself.
  1172.  
  1173.     if (mAGAObject != NULL)
  1174.         {
  1175.         this->FocusDraw();
  1176.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  1177.         }
  1178.     }
  1179.  
  1180. void AGARadioButtonPP::ShowSelf()
  1181.     {
  1182.     // Suppress showing the Control Manager control.
  1183.     }
  1184.  
  1185. void AGARadioButtonPP::SetValue(SInt32 inValue)
  1186.     {
  1187.     // Set the actual LControl value and the AGA object value.
  1188.  
  1189.     Inherited::SetValue(inValue);
  1190.  
  1191.     if (mAGAObject != NULL)
  1192.         {
  1193.         this->FocusDraw();
  1194.         mAGAObject->SetValue(mValue, this->IsVisible());
  1195.         }
  1196.     }
  1197.  
  1198. void AGARadioButtonPP::CreateAGAObject()
  1199.     {
  1200.     // Instantiate the particular AGAObject subclass.
  1201.  
  1202.     Rect    bounds;
  1203.     Str255    title;
  1204.     
  1205.     (void) this->CalcLocalFrameRect(bounds);
  1206.     ::GetControlTitle(mMacControlH, title);
  1207.  
  1208.     ThrowIfNil_(mAGAObject = new AGARadioButton(&bounds, AGATextStyle(mTextTraitsID), title, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState));
  1209.  
  1210.     if (mEnabled == triState_Off)
  1211.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1212.  
  1213.     mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
  1214.     }
  1215.  
  1216. //
  1217. // AGAIconPushButtonPP ----------------------------------------------------
  1218. //
  1219.  
  1220. #undef Inherited
  1221. #define Inherited AGAPushButtonPP
  1222.  
  1223. AGAIconPushButtonPP* AGAIconPushButtonPP::CreateStream(LStream* inStream)
  1224.     {
  1225.     return new AGAIconPushButtonPP(inStream);
  1226.     }
  1227.  
  1228. AGAIconPushButtonPP::AGAIconPushButtonPP()
  1229.     {
  1230.     mIconID = MIconButtonObject::kNoIconID;
  1231.     mFrameType = MIconButtonObject::kAutoFrame;
  1232.     mImageType = MIconButtonObject::kAutoIconFamily;
  1233.     }
  1234.  
  1235. AGAIconPushButtonPP::AGAIconPushButtonPP(LStream* inStream)
  1236. : Inherited(inStream)
  1237.     {
  1238.     // Use the mUserCon for the icon ID.
  1239.  
  1240.     mIconID = mUserCon;
  1241.     mFrameType = MIconButtonObject::kAutoFrame;
  1242.     mImageType = MIconButtonObject::kAutoIconFamily;
  1243.     }
  1244.  
  1245. AGAIconPushButtonPP::~AGAIconPushButtonPP()
  1246.     {
  1247.     }
  1248.  
  1249. void AGAIconPushButtonPP::CreateAGAObject()
  1250.     {
  1251.     // Instantiate the particular AGAObject subclass.
  1252.  
  1253.     Rect    bounds;
  1254.     
  1255.     (void) this->CalcLocalFrameRect(bounds);
  1256.  
  1257.     ThrowIfNil_(mAGAObject = new AGAIconPushButton(&bounds, mIconID, mFrameType, mImageType));
  1258.  
  1259.     if (mEnabled == triState_Off)
  1260.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1261.     }
  1262.  
  1263. //
  1264. // AGAIconPushButtonPPX ----------------------------------------------------
  1265. //
  1266.  
  1267. #undef Inherited
  1268. #define Inherited AGAIconPushButtonPP
  1269.  
  1270. AGAIconPushButtonPPX* AGAIconPushButtonPPX::CreateStream(LStream* inStream)
  1271.     {
  1272.     return new AGAIconPushButtonPPX(inStream);
  1273.     }
  1274.  
  1275. AGAIconPushButtonPPX::AGAIconPushButtonPPX(LStream* inStream)
  1276. : Inherited(inStream)
  1277.     {
  1278.     // Read the icon ID, frame type, and image type from the stream.
  1279.  
  1280.     inStream->ReadData(&mIconID, sizeof(mIconID));
  1281.     inStream->ReadData(&mFrameType, sizeof(mFrameType));
  1282.     inStream->ReadData(&mImageType, sizeof(mImageType));
  1283.     }
  1284.  
  1285. AGAIconPushButtonPPX::~AGAIconPushButtonPPX()
  1286.     {
  1287.     }
  1288.  
  1289. //
  1290. // AGAIconCheckBoxPP ----------------------------------------------------
  1291. //
  1292.  
  1293. #undef Inherited
  1294. #define Inherited AGACheckBoxPP
  1295.  
  1296. AGAIconCheckBoxPP* AGAIconCheckBoxPP::CreateStream(LStream* inStream)
  1297.     {
  1298.     return new AGAIconCheckBoxPP(inStream);
  1299.     }
  1300.  
  1301. AGAIconCheckBoxPP::AGAIconCheckBoxPP()
  1302.     {
  1303.     mOffIconID = MIconButtonObject::kNoIconID;
  1304.     mOnIconID = MIconButtonObject::kNoIconID;
  1305.     mFrameType = MIconButtonObject::kAutoFrame;
  1306.     mImageType = MIconButtonObject::kAutoIconFamily;
  1307.     }
  1308.  
  1309. AGAIconCheckBoxPP::AGAIconCheckBoxPP(LStream* inStream)
  1310. : Inherited(inStream)
  1311.     {
  1312.     // Use the mUserCon for both icon IDs.
  1313.  
  1314.     mOffIconID = mUserCon;
  1315.     mOnIconID = mUserCon;
  1316.     mFrameType = MIconButtonObject::kAutoFrame;
  1317.     mImageType = MIconButtonObject::kAutoIconFamily;
  1318.     }
  1319.  
  1320. AGAIconCheckBoxPP::~AGAIconCheckBoxPP()
  1321.     {
  1322.     }
  1323.  
  1324. void AGAIconCheckBoxPP::CreateAGAObject()
  1325.     {
  1326.     // Instantiate the particular AGAObject subclass.
  1327.     Rect    bounds;
  1328.     
  1329.     (void) this->CalcLocalFrameRect(bounds);
  1330.  
  1331.     ThrowIfNil_(mAGAObject = new AGAIconCheckBox(&bounds, AGAObject::kNoAutomaticState, mOffIconID, mOnIconID, mFrameType, mImageType));
  1332.  
  1333.     if (mEnabled == triState_Off)
  1334.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1335.  
  1336.     mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
  1337.     }
  1338.  
  1339. //
  1340. // AGAIconCheckBoxPPX ----------------------------------------------------
  1341. //
  1342.  
  1343. #undef Inherited
  1344. #define Inherited AGAIconCheckBoxPP
  1345.  
  1346. AGAIconCheckBoxPPX* AGAIconCheckBoxPPX::CreateStream(LStream* inStream)
  1347.     {
  1348.     return new AGAIconCheckBoxPPX(inStream);
  1349.     }
  1350.  
  1351. AGAIconCheckBoxPPX::AGAIconCheckBoxPPX(LStream* inStream)
  1352. : Inherited(inStream)
  1353.     {
  1354.     // Read the icon IDs, frame type, and image type from the stream.
  1355.  
  1356.     inStream->ReadData(&mOffIconID, sizeof(mOffIconID));
  1357.     inStream->ReadData(&mOnIconID, sizeof(mOnIconID));
  1358.     inStream->ReadData(&mFrameType, sizeof(mFrameType));
  1359.     inStream->ReadData(&mImageType, sizeof(mImageType));
  1360.     }
  1361.  
  1362. AGAIconCheckBoxPPX::~AGAIconCheckBoxPPX()
  1363.     {
  1364.     }
  1365.  
  1366. //
  1367. // AGAIconRadioButtonPP ----------------------------------------------------
  1368. //
  1369.  
  1370. #undef Inherited
  1371. #define Inherited AGARadioButtonPP
  1372.  
  1373. AGAIconRadioButtonPP* AGAIconRadioButtonPP::CreateStream(LStream* inStream)
  1374.     {
  1375.     return new AGAIconRadioButtonPP(inStream);
  1376.     }
  1377.  
  1378. AGAIconRadioButtonPP::AGAIconRadioButtonPP()
  1379.     {
  1380.     mOffIconID = MIconButtonObject::kNoIconID;
  1381.     mOnIconID = MIconButtonObject::kNoIconID;
  1382.     mFrameType = MIconButtonObject::kAutoFrame;
  1383.     mImageType = MIconButtonObject::kAutoIconFamily;
  1384.     }
  1385.  
  1386. AGAIconRadioButtonPP::AGAIconRadioButtonPP(LStream* inStream)
  1387. : Inherited(inStream)
  1388.     {
  1389.     // Use the mUserCon for both icon IDs.
  1390.  
  1391.     mOffIconID = mUserCon;
  1392.     mOnIconID = mUserCon;
  1393.     mFrameType = MIconButtonObject::kAutoFrame;
  1394.     mImageType = MIconButtonObject::kAutoIconFamily;
  1395.     }
  1396.  
  1397. AGAIconRadioButtonPP::~AGAIconRadioButtonPP()
  1398.     {
  1399.     }
  1400.  
  1401. void AGAIconRadioButtonPP::CreateAGAObject()
  1402.     {
  1403.     // Instantiate the particular AGAObject subclass.
  1404.     Rect    bounds;
  1405.     
  1406.     (void) this->CalcLocalFrameRect(bounds);
  1407.  
  1408.     ThrowIfNil_(mAGAObject = new AGAIconRadioButton(&bounds, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState, mOffIconID, mOnIconID, mFrameType, mImageType));
  1409.  
  1410.     if (mEnabled == triState_Off)
  1411.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1412.  
  1413.     mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
  1414.     }
  1415.  
  1416. //
  1417. // AGAIconRadioButtonPPX ----------------------------------------------------
  1418. //
  1419.  
  1420. #undef Inherited
  1421. #define Inherited AGAIconRadioButtonPP
  1422.  
  1423. AGAIconRadioButtonPPX* AGAIconRadioButtonPPX::CreateStream(LStream* inStream)
  1424.     {
  1425.     return new AGAIconRadioButtonPPX(inStream);
  1426.     }
  1427.  
  1428. AGAIconRadioButtonPPX::AGAIconRadioButtonPPX(LStream* inStream)
  1429. : Inherited(inStream)
  1430.     {
  1431.     // Read the icon IDs, frame type, and image type from the stream.
  1432.  
  1433.     inStream->ReadData(&mOffIconID, sizeof(mOffIconID));
  1434.     inStream->ReadData(&mOnIconID, sizeof(mOnIconID));
  1435.     inStream->ReadData(&mFrameType, sizeof(mFrameType));
  1436.     inStream->ReadData(&mImageType, sizeof(mImageType));
  1437.     }
  1438.  
  1439. AGAIconRadioButtonPPX::~AGAIconRadioButtonPPX()
  1440.     {
  1441.     }
  1442.  
  1443. //
  1444. // AGAGroupBoxPP ----------------------------------------------------
  1445. //
  1446.  
  1447. #undef Inherited
  1448. #define Inherited LGroupBox
  1449.  
  1450. AGAGroupBoxPP* AGAGroupBoxPP::CreateStream(LStream* inStream)
  1451.     {
  1452.     return new AGAGroupBoxPP(inStream);
  1453.     }
  1454.  
  1455. AGAGroupBoxPP::AGAGroupBoxPP()
  1456.     {
  1457.     // Assume primary group type, no gap pane.
  1458.  
  1459.     mAGAObject = NULL;
  1460.     mIsPrimaryGroup = true;
  1461.     mGapPaneID = 0;
  1462.     }
  1463.  
  1464. AGAGroupBoxPP::AGAGroupBoxPP(LStream* inStream)
  1465. : Inherited(inStream)
  1466.     {
  1467.     // Assume primary group type, and use the mUserCon as the
  1468.     // gap pane's ID.
  1469.  
  1470.     mAGAObject = NULL;
  1471.     mIsPrimaryGroup = true;
  1472.     mGapPaneID = mUserCon;
  1473.     }
  1474.  
  1475. AGAGroupBoxPP::~AGAGroupBoxPP()
  1476.     {
  1477.     // Delete AGA object if we successfully allocated it.
  1478.  
  1479.     if (mAGAObject != NULL)
  1480.         delete mAGAObject;
  1481.     }
  1482.  
  1483. void AGAGroupBoxPP::SetDescriptor(ConstStringPtr inDescriptor)
  1484.     {
  1485.     Inherited::SetDescriptor(inDescriptor);
  1486.     
  1487.     // Install the new text in the AGA object. Don't tell it
  1488.     // to redraw; the redraw comes from the caller.
  1489.  
  1490.     Str255    newText;
  1491.     this->GetDescriptor(newText);
  1492.     mAGAObject->SetTitle(newText, AGAObject::kDontRedraw);
  1493.     }
  1494.  
  1495. void AGAGroupBoxPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  1496.     {
  1497.     // Let the PowerPlant and AGA objects update their bounds.
  1498.  
  1499.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  1500.     
  1501.     ResetAGAObjectFrame(this, mAGAObject);
  1502.     }
  1503.  
  1504. void AGAGroupBoxPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  1505.     {
  1506.     // Let the PowerPlant and AGA objects update their bounds.
  1507.  
  1508.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  1509.     
  1510.     ResetAGAObjectFrame(this, mAGAObject);
  1511.     }
  1512.  
  1513. void AGAGroupBoxPP::FinishCreateSelf()
  1514.     {
  1515.     // Create and set up the AGAObject.
  1516.  
  1517.     this->CreateAGAObject();
  1518.     }
  1519.  
  1520. void AGAGroupBoxPP::DrawSelf()
  1521.     {
  1522.     // Let the AGAObject draw itself.
  1523.  
  1524.     if (mAGAObject != NULL)
  1525.         mAGAObject->DrawObject();
  1526.     }
  1527.  
  1528. void AGAGroupBoxPP::EnableSelf()
  1529.     {
  1530.     // Let the AGAObject enable itself.
  1531.  
  1532.     if (mAGAObject != NULL)
  1533.         {
  1534.         this->FocusDraw();
  1535.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  1536.         }
  1537.     }
  1538.  
  1539. void AGAGroupBoxPP::DisableSelf()
  1540.     {
  1541.     // Let the AGAObject disable itself.
  1542.  
  1543.     if (mAGAObject != NULL)
  1544.         {
  1545.         this->FocusDraw();
  1546.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  1547.         }
  1548.     }
  1549.  
  1550. void AGAGroupBoxPP::CreateAGAObject()
  1551.     {
  1552.     // Instantiate the particular AGAObject subclass.
  1553.  
  1554.     Rect    bounds;
  1555.     
  1556.     (void) this->CalcLocalFrameRect(bounds);
  1557.  
  1558.     ThrowIfNil_(mAGAObject = new AGAGroupBox(&bounds, AGATextStyle(mTxtrID), mIsPrimaryGroup, mText));
  1559.  
  1560.     if (mEnabled == triState_Off)
  1561.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1562.  
  1563.     if ((mGapPaneID != 0) && (this->GetSuperView() != NULL))
  1564.         {
  1565.         LPane*    gapPane = this->GetSuperView()->FindPaneByID(mGapPaneID);
  1566.  
  1567.         if (gapPane != NULL)
  1568.             {
  1569.             Rect    bounds;
  1570.             
  1571.             (void) gapPane->CalcLocalFrameRect(bounds);
  1572.  
  1573.             mAGAObject->SetTitleGap(5 + bounds.right - bounds.left);
  1574.             }
  1575.         }
  1576.     }
  1577.  
  1578. //
  1579. // AGAGroupBoxPPX ----------------------------------------------------
  1580. //
  1581.  
  1582. #undef Inherited
  1583. #define Inherited AGAGroupBoxPP
  1584.  
  1585. AGAGroupBoxPPX* AGAGroupBoxPPX::CreateStream(LStream* inStream)
  1586.     {
  1587.     return new AGAGroupBoxPPX(inStream);
  1588.     }
  1589.  
  1590. AGAGroupBoxPPX::AGAGroupBoxPPX(LStream* inStream)
  1591. : Inherited(inStream)
  1592.     {
  1593.     // Read the group type and gap pane ID from the stream.
  1594.  
  1595.     inStream->ReadData(&mIsPrimaryGroup, sizeof(mIsPrimaryGroup));
  1596.     inStream->ReadData(&mGapPaneID, sizeof(mGapPaneID));
  1597.     }
  1598.  
  1599. AGAGroupBoxPPX::~AGAGroupBoxPPX()
  1600.     {
  1601.     }
  1602.  
  1603. //
  1604. // AGASecondaryGroupBoxPP ----------------------------------------------------
  1605. //
  1606.  
  1607. #undef Inherited
  1608. #define Inherited AGAGroupBoxPP
  1609.  
  1610. AGASecondaryGroupBoxPP* AGASecondaryGroupBoxPP::CreateStream(LStream* inStream)
  1611.     {
  1612.     return new AGASecondaryGroupBoxPP(inStream);
  1613.     }
  1614.  
  1615. AGASecondaryGroupBoxPP::AGASecondaryGroupBoxPP()
  1616.     {
  1617.     // Set to secondary group box type. Will be used when AGA object
  1618.     // is created.
  1619.  
  1620.     mIsPrimaryGroup = false;
  1621.     }
  1622.  
  1623. AGASecondaryGroupBoxPP::AGASecondaryGroupBoxPP(LStream* inStream)
  1624. : Inherited(inStream)
  1625.     {
  1626.     // Set to secondary group box type. Will be used when AGA object
  1627.     // is created.
  1628.  
  1629.     mIsPrimaryGroup = false;
  1630.     }
  1631.  
  1632. AGASecondaryGroupBoxPP::~AGASecondaryGroupBoxPP()
  1633.     {
  1634.     }
  1635.  
  1636. //
  1637. // AGAScrollBarPP ----------------------------------------------------
  1638. //
  1639.  
  1640. #undef Inherited
  1641. #define Inherited LStdControl
  1642.  
  1643. AGAScrollBarPP* AGAScrollBarPP::CreateStream(LStream* inStream)
  1644.     {
  1645.     return new AGAScrollBarPP(inStream);
  1646.     }
  1647.  
  1648. AGAScrollBarPP::AGAScrollBarPP()
  1649.     {
  1650.     mAGAObject = NULL;
  1651.     mNotificationRoutine = NULL;
  1652.     mUserData = 0;
  1653.     mInitWithLiveScrolling = AGAObject::kNoLiveTracking;
  1654.     }
  1655.  
  1656. AGAScrollBarPP::AGAScrollBarPP(LStream* inStream)
  1657. : Inherited(inStream)
  1658.     {
  1659.     mAGAObject = NULL;
  1660.     mNotificationRoutine = NULL;
  1661.     mUserData = 0;
  1662.     mInitWithLiveScrolling = AGAObject::kNoLiveTracking;
  1663.     }
  1664.  
  1665. AGAScrollBarPP::AGAScrollBarPP(const SPaneInfo    &inPaneInfo,
  1666.                         MessageT        inValueMessage,
  1667.                         Int32            inValue,
  1668.                         Int32            inMinValue,
  1669.                         Int32            inMaxValue,
  1670.                         Int16            inControlKind,
  1671.                         ResIDT            inTextTraitsID,
  1672.                         Str255            inTitle,
  1673.                         Int32            inMacRefCon,
  1674.                         Boolean            liveScrolling)
  1675. : Inherited(inPaneInfo, inValueMessage, inValue, inMinValue, inMaxValue, inControlKind, inTextTraitsID, inTitle, inMacRefCon)
  1676.     {
  1677.     mAGAObject = NULL;
  1678.     mNotificationRoutine = NULL;
  1679.     mUserData = 0;
  1680.     mInitWithLiveScrolling = liveScrolling;
  1681.     }
  1682.  
  1683. AGAScrollBarPP::~AGAScrollBarPP()
  1684.     {
  1685.     // Delete AGA object if we successfully allocated it.
  1686.  
  1687.     if (mAGAObject != NULL)
  1688.         delete mAGAObject;
  1689.     }
  1690.  
  1691. void AGAScrollBarPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  1692.     {
  1693.     // Let the PowerPlant and AGA objects update their bounds.
  1694.  
  1695.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  1696.     
  1697.     ResetAGAObjectFrame(this, mAGAObject);
  1698.     }
  1699.  
  1700. void AGAScrollBarPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  1701.     {
  1702.     // Let the PowerPlant and AGA objects update their bounds.
  1703.  
  1704.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  1705.     
  1706.     ResetAGAObjectFrame(this, mAGAObject);
  1707.     }
  1708.  
  1709. void AGAScrollBarPP::InstallNotificationRoutine(AGANotifyPPPtr notificationRoutine, void* userData)
  1710.     {
  1711.     // Save the notification routine fn pointer and user data
  1712.     // for notification handling.
  1713.  
  1714.     mNotificationRoutine = notificationRoutine;
  1715.     mUserData = userData;
  1716.     }
  1717.  
  1718. void AGAScrollBarPP::HandleNotification(SInt32 dataValue)
  1719.     {
  1720.     // Update the scrollbar value, call the installed notification
  1721.     // function, and propagate our event number.
  1722.  
  1723.     this->SetValue(dataValue);
  1724.  
  1725.     if (mNotificationRoutine != NULL)
  1726.         (*mNotificationRoutine)(this, dataValue, mUserData);
  1727.  
  1728.     this->BroadcastValueMessage();
  1729.  
  1730.     (void) this->FocusDraw();    // HandleEvent may have caused another view to draw
  1731.     }
  1732.  
  1733. void AGAScrollBarPP::FinishCreateSelf()
  1734.     {
  1735.     // Create and set up the AGAObject.
  1736.  
  1737.     this->HideSelf();    // make sure the Control Manager object is not drawn
  1738.  
  1739.     this->CreateAGAObject();
  1740.     }
  1741.  
  1742. void AGAScrollBarPP::DrawSelf()
  1743.     {
  1744.     // Let the AGAObject draw itself.
  1745.  
  1746.     if (mAGAObject != NULL)
  1747.         mAGAObject->DrawObject();
  1748.     }
  1749.  
  1750. void AGAScrollBarPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  1751.     {
  1752.     // Let the AGAObject track the mouse.
  1753.  
  1754.     if (mAGAObject != NULL)
  1755.         {
  1756.         this->FocusDraw();
  1757.         
  1758.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  1759.             this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
  1760.         }
  1761.     }
  1762.  
  1763. void AGAScrollBarPP::EnableSelf()
  1764.     {
  1765.     // Let the AGAObject enable itself.
  1766.  
  1767.     if (mAGAObject != NULL)
  1768.         {
  1769.         this->FocusDraw();
  1770.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  1771.         }
  1772.     }
  1773.  
  1774. void AGAScrollBarPP::DisableSelf()
  1775.     {
  1776.     // Let the AGAObject disable itself.
  1777.  
  1778.     if (mAGAObject != NULL)
  1779.         {
  1780.         this->FocusDraw();
  1781.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  1782.         }
  1783.     }
  1784.  
  1785. void AGAScrollBarPP::ShowSelf()
  1786.     {
  1787.     // Suppress showing the Control Manager control.
  1788.     }
  1789.  
  1790. void AGAScrollBarPP::CreateAGAObject()
  1791.     {
  1792.     // Instantiate the particular AGAObject subclass.
  1793.  
  1794.     Rect    bounds;
  1795.     
  1796.     (void) this->CalcLocalFrameRect(bounds);
  1797.  
  1798.     ThrowIfNil_(mAGAObject = new AGAScrollBar(&bounds, mMinValue, mMaxValue, mValue));
  1799.     
  1800.     mAGAObject->SetLiveTracking(mInitWithLiveScrolling);
  1801.  
  1802.     mAGAObject->InstallNotificationRoutine(AGAScrollBarPP::RealAGANotifier, this);
  1803.  
  1804.     if (mEnabled == triState_Off)
  1805.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1806.     }
  1807.  
  1808. void AGAScrollBarPP::SetValue(SInt32 inValue)
  1809.     {
  1810.     // Set the LStdControl value and the AGA object value.
  1811.  
  1812.     Inherited::SetValue(inValue);
  1813.  
  1814.     if (mAGAObject != NULL)
  1815.         {
  1816.         this->FocusDraw();
  1817.         
  1818.         mAGAObject->SetValue(mValue, this->IsVisible());
  1819.         }
  1820.     }
  1821.  
  1822. void AGAScrollBarPP::SetMinValue(SInt32 inMinValue)
  1823.     {
  1824.     // Set the LStdControl min and the AGA object min.
  1825.  
  1826.     Inherited::SetMinValue(inMinValue);
  1827.  
  1828.     if (mAGAObject != NULL)
  1829.         {
  1830.         SInt32    oldMin;
  1831.         SInt32    oldMax;
  1832.  
  1833.         this->FocusDraw();
  1834.         
  1835.         mAGAObject->GetRange(&oldMin, &oldMax);
  1836.         mAGAObject->SetRange(inMinValue, oldMax, this->IsVisible());
  1837.         }
  1838.     }
  1839.  
  1840. void AGAScrollBarPP::SetMaxValue(SInt32 inMaxValue)
  1841.     {
  1842.     // Set the LStdControl max and the AGA object max.
  1843.  
  1844.     Inherited::SetMaxValue(inMaxValue);
  1845.  
  1846.     if (mAGAObject != NULL)
  1847.         {
  1848.         SInt32    oldMin;
  1849.         SInt32    oldMax;
  1850.  
  1851.         this->FocusDraw();
  1852.         
  1853.         mAGAObject->GetRange(&oldMin, &oldMax);
  1854.         mAGAObject->SetRange(oldMin, inMaxValue, this->IsVisible());
  1855.         }
  1856.     }
  1857.  
  1858. void AGAScrollBarPP::RealAGANotifier(AGATrackingIndicator* /*theIndicator*/, SInt32 dataValue, void* userData)
  1859.     {
  1860.     // This is a static function. Cast the user data to get
  1861.     // the AGAScrollBarPP object, have it handle the notification.
  1862.  
  1863.     ((AGAScrollBarPP*) userData)->HandleNotification(dataValue);
  1864.     }
  1865.  
  1866. //
  1867. // AGAScrollerPP ----------------------------------------------------
  1868. //
  1869.  
  1870. #undef Inherited
  1871. #define Inherited LScroller
  1872.  
  1873. AGAScrollerPP* AGAScrollerPP::CreateStream(LStream* inStream)
  1874.     {
  1875.     return new AGAScrollerPP(inStream);
  1876.     }
  1877.  
  1878. AGAScrollerPP::AGAScrollerPP()
  1879.     {
  1880.     mOldHorizontalBar = NULL;
  1881.     mOldVerticalBar = NULL;
  1882.     }
  1883.  
  1884. AGAScrollerPP::AGAScrollerPP(LStream* inStream)
  1885. : Inherited(inStream)
  1886.     {
  1887.     mOldHorizontalBar = NULL;
  1888.     mOldVerticalBar = NULL;
  1889.  
  1890.     //
  1891.     // Back up in the stream so we can find out what the
  1892.     // scroll bar indents are.
  1893.     //
  1894.  
  1895.     inStream->SetMarker(-sizeof(SScrollerInfo), streamFrom_Marker);
  1896.  
  1897.     SScrollerInfo    scrollerInfo;
  1898.     inStream->ReadData(&scrollerInfo, sizeof(SScrollerInfo));
  1899.     
  1900.     //
  1901.     // Replace the standard scroll bars with AGA scroll bars.
  1902.     //
  1903.     
  1904.     this->MakeCustomScrollBars(scrollerInfo.horizBarLeftIndent,
  1905.                                scrollerInfo.horizBarRightIndent,
  1906.                                scrollerInfo.vertBarTopIndent,
  1907.                                scrollerInfo.vertBarBottomIndent,
  1908.                                AGAObject::kNoLiveTracking);
  1909.     }
  1910.  
  1911. AGAScrollerPP::AGAScrollerPP(LStream* inStream, Boolean liveTracking)
  1912. : Inherited(inStream)
  1913.     {
  1914.     mOldHorizontalBar = NULL;
  1915.     mOldVerticalBar = NULL;
  1916.  
  1917.     //
  1918.     // Back up in the stream so we can find out what the
  1919.     // scroll bar indents are.
  1920.     //
  1921.  
  1922.     inStream->SetMarker(-sizeof(SScrollerInfo), streamFrom_Marker);
  1923.  
  1924.     SScrollerInfo    scrollerInfo;
  1925.     inStream->ReadData(&scrollerInfo, sizeof(SScrollerInfo));
  1926.     
  1927.     //
  1928.     // Replace the standard scroll bars with AGA scroll bars.
  1929.     //
  1930.     
  1931.     this->MakeCustomScrollBars(scrollerInfo.horizBarLeftIndent,
  1932.                                scrollerInfo.horizBarRightIndent,
  1933.                                scrollerInfo.vertBarTopIndent,
  1934.                                scrollerInfo.vertBarBottomIndent,
  1935.                                liveTracking);
  1936.     }
  1937.  
  1938. AGAScrollerPP::~AGAScrollerPP()
  1939.     {
  1940.     }
  1941.  
  1942. void AGAScrollerPP::FinishCreateSelf()
  1943.     {
  1944.     Inherited::FinishCreateSelf();
  1945.     
  1946.     //
  1947.     // We can now safely delete the standard scroll bar objects
  1948.     // that we have replaced with AGA scroll bars.
  1949.     //
  1950.  
  1951.     if (mOldHorizontalBar != NULL)
  1952.         {
  1953.         mOldHorizontalBar->Hide();
  1954.         delete mOldHorizontalBar;
  1955.         mOldHorizontalBar = NULL;
  1956.         }
  1957.  
  1958.     if (mOldVerticalBar != NULL)
  1959.         {
  1960.         mOldVerticalBar->Hide();
  1961.         delete mOldVerticalBar;
  1962.         mOldVerticalBar = NULL;
  1963.         }
  1964.     }
  1965.  
  1966. void AGAScrollerPP::MakeCustomScrollBars(
  1967.     Int16            inHorizBarLeftIndent,
  1968.     Int16            inHorizBarRightIndent,
  1969.     Int16            inVertBarTopIndent,
  1970.     Int16            inVertBarBottomIndent,
  1971.     Boolean            liveTracking)
  1972. {
  1973. //
  1974. // NOTE: This code is lifted from LScroller::MakeScrollBars,
  1975. // modified to create our scroll bars of our AGAScrollBarPP class
  1976. // and use our form of notification that supports live scrolling.
  1977. //
  1978.  
  1979.     SPaneInfo    barInfo;                // Common information for ScrollBars
  1980.     barInfo.visible = false;            // ScrollBars aren't visible until
  1981.     barInfo.enabled = true;                //    Scroller is activated
  1982.     barInfo.userCon = 0;
  1983.     barInfo.superView = this;
  1984.     
  1985.     mOldHorizontalBar = mHorizontalBar;
  1986.     
  1987.     mHorizontalBar = nil;
  1988.     if (inHorizBarLeftIndent >= 0) {
  1989.                                         // Create Horizontal ScrollBar
  1990.         barInfo.paneID = PaneIDT_HorizontalScrollBar;    
  1991.         barInfo.width = mFrameSize.width - inHorizBarLeftIndent -
  1992.                                            inHorizBarRightIndent;
  1993.         barInfo.height = 16;
  1994.         barInfo.bindings.left = true;
  1995.         barInfo.bindings.right = true;
  1996.         barInfo.bindings.top = false;
  1997.         barInfo.bindings.bottom = true;
  1998.         barInfo.left = inHorizBarLeftIndent;
  1999.         barInfo.top = mFrameSize.height - 16;
  2000.  
  2001.         mHorizontalBar = this->MakeCustomScrollBar(barInfo, liveTracking);
  2002.  
  2003.         ((AGAScrollBarPP*) mHorizontalBar)->InstallNotificationRoutine(AGAScrollerPP::ScrollBarNotifier, this);
  2004.     }
  2005.  
  2006.     mOldVerticalBar = mVerticalBar;
  2007.     
  2008.     mVerticalBar = nil;
  2009.     if (inVertBarTopIndent >= 0) {
  2010.                                         // Create Vertical ScrollBar
  2011.         barInfo.paneID = PaneIDT_VerticalScrollBar;    
  2012.         barInfo.width = 16;
  2013.         barInfo.height = mFrameSize.height - inVertBarTopIndent -
  2014.                                              inVertBarBottomIndent;
  2015.         barInfo.bindings.left = false;
  2016.         barInfo.bindings.right = true;
  2017.         barInfo.bindings.top = true;
  2018.         barInfo.bindings.bottom = true;
  2019.         barInfo.left = mFrameSize.width - 16;
  2020.         barInfo.top = inVertBarTopIndent;
  2021.  
  2022.         mVerticalBar = this->MakeCustomScrollBar(barInfo, liveTracking);
  2023.  
  2024.         ((AGAScrollBarPP*) mVerticalBar)->InstallNotificationRoutine(AGAScrollerPP::ScrollBarNotifier, this);
  2025.     }
  2026. }
  2027.  
  2028. AGAScrollBarPP*    AGAScrollerPP::MakeCustomScrollBar(const SPaneInfo& barInfo, Boolean liveTracking)
  2029.     {
  2030.     return new AGAScrollBarPP(barInfo, msg_Nothing, 0, 0, 0,
  2031.                                 scrollBarProc, 0, "\p", (Int32) this,
  2032.                                 liveTracking);
  2033.     }
  2034.  
  2035. void AGAScrollerPP::HandleNotification(LPane* theScrollBar, SInt32 dataValue)
  2036.     {
  2037.     // Scroll the image to the new location specified.
  2038.     // This is similar to what LScroller does when it listens
  2039.     // to a thumb drag message.
  2040.  
  2041.     SPoint32    newScrollPosition;
  2042.     
  2043.     mScrollingView->GetScrollPosition(newScrollPosition);
  2044.  
  2045.     if (theScrollBar == mHorizontalBar)
  2046.         newScrollPosition.h = dataValue;
  2047.     else if (theScrollBar == mVerticalBar)
  2048.         newScrollPosition.v = dataValue;
  2049.  
  2050.     mScrollingView->ScrollImageTo(newScrollPosition.h, newScrollPosition.v, true);
  2051.     this->AdjustScrollBars();
  2052.  
  2053.     (void) this->FocusDraw();    // scrolling view may have grabbed focus
  2054.     }
  2055.  
  2056. void AGAScrollerPP::AdjustScrollBars()
  2057.     {
  2058.     // Check the scrolling view's size compared to ours, so that
  2059.     // the scroll bars have to correct page and step sizes.
  2060.  
  2061.     AGAScrollBarPP*    horizontalBar = (AGAScrollBarPP*) mHorizontalBar;
  2062.     AGAScrollBarPP*    verticalBar = (AGAScrollBarPP*) mVerticalBar;
  2063.  
  2064.     SPoint32        scrollUnit;
  2065.     SDimension16    scrollFrameSize;
  2066.     SDimension32    scrollImageSize;
  2067.     SPoint32        scrollPosition;
  2068.     SPoint32        maxTranslation;
  2069.     SPoint32        pageStepSize;
  2070.     SPoint32        pageSize;
  2071.  
  2072.     mScrollingView->GetScrollUnit(scrollUnit);
  2073.     mScrollingView->GetFrameSize(scrollFrameSize);
  2074.     mScrollingView->GetImageSize(scrollImageSize);
  2075.     mScrollingView->GetScrollPosition(scrollPosition);
  2076.     
  2077.     // The maxTranslation is the max (pinned) scroll value.
  2078.     maxTranslation.h = scrollImageSize.width - scrollFrameSize.width;
  2079.     maxTranslation.v = scrollImageSize.height - scrollFrameSize.height;
  2080.     
  2081.     // The page step size is how far to scroll page scrolling
  2082.     pageStepSize.h = MaxSInt32(0, scrollFrameSize.width - scrollUnit.h);
  2083.     pageStepSize.v = MaxSInt32(0, scrollFrameSize.height - scrollUnit.v);
  2084.  
  2085.     // The page size is the range that is visible at once.
  2086.     // It's not the same as the page step size.
  2087.     if (scrollImageSize.width < 1)    // avoid divide by zero or weird negatives
  2088.         pageSize.h = 1;
  2089.     else
  2090.         pageSize.h = maxTranslation.h *
  2091.             (((float) scrollFrameSize.width) / ((float) scrollImageSize.width));
  2092.  
  2093.     if (scrollImageSize.height < 1)    // avoid divide by zero or weird negatives
  2094.         pageSize.v = 1;
  2095.     else
  2096.         pageSize.v = maxTranslation.v *
  2097.             (((float) scrollFrameSize.height) / ((float) scrollImageSize.height));
  2098.  
  2099.     // Update the scroll bar objects with the calculated values.
  2100.  
  2101.     if (horizontalBar != NULL)
  2102.         {
  2103.         horizontalBar->FocusDraw();
  2104.         horizontalBar->SetMaxValue(maxTranslation.h);
  2105.         horizontalBar->mAGAObject->SetPageSize(pageSize.h, horizontalBar->IsVisible());
  2106.         horizontalBar->mAGAObject->SetStepSizes(scrollUnit.h, pageStepSize.h);
  2107.         horizontalBar->SetValue(scrollPosition.h);
  2108.         }
  2109.  
  2110.     if (verticalBar != NULL)
  2111.         {
  2112.         verticalBar->FocusDraw();
  2113.         verticalBar->SetMaxValue(maxTranslation.v);
  2114.         verticalBar->mAGAObject->SetPageSize(pageSize.v, verticalBar->IsVisible());
  2115.         verticalBar->mAGAObject->SetStepSizes(scrollUnit.v, pageStepSize.v);
  2116.         verticalBar->SetValue(scrollPosition.v);
  2117.         }
  2118.     }
  2119.  
  2120. void AGAScrollerPP::ScrollBarNotifier(LPane* theScrollBar, SInt32 dataValue, void* userData)
  2121.     {
  2122.     // This is a static function. Cast the user data to get
  2123.     // the AGAScrollBarPP object, have it handle the notification.
  2124.  
  2125.     ((AGAScrollerPP*) userData)->HandleNotification(theScrollBar, dataValue);
  2126.     }
  2127.  
  2128. //
  2129. // AGAActiveScrollerPP ----------------------------------------------------
  2130. //
  2131.  
  2132. #undef Inherited
  2133. #define Inherited AGAScrollerPP
  2134.  
  2135. AGAActiveScrollerPP* AGAActiveScrollerPP::CreateStream(LStream* inStream)
  2136.     {
  2137.     return new AGAActiveScrollerPP(inStream);
  2138.     }
  2139.  
  2140. AGAActiveScrollerPP::AGAActiveScrollerPP()
  2141.     {
  2142.     }
  2143.  
  2144. AGAActiveScrollerPP::AGAActiveScrollerPP(LStream* inStream)
  2145. : Inherited(inStream, AGAObject::kLiveTracking)
  2146.     {
  2147.     }
  2148.  
  2149. AGAActiveScrollerPP::~AGAActiveScrollerPP()
  2150.     {
  2151.     }
  2152.  
  2153. //
  2154. // AGASliderPP ----------------------------------------------------
  2155. //
  2156.  
  2157. #pragma segment GrayCouncilPP2
  2158.  
  2159. #undef Inherited
  2160. #define Inherited LControl
  2161.  
  2162. AGASliderPP* AGASliderPP::CreateStream(LStream* inStream)
  2163.     {
  2164.     return new AGASliderPP(inStream);
  2165.     }
  2166.  
  2167. AGASliderPP::AGASliderPP()
  2168.     {
  2169.     mAGAObject = NULL;
  2170.     mNotificationRoutine = NULL;
  2171.     mUserData = 0;
  2172.     mLabelsResourceID = 0;            // STR# resource ID of the slider labels (0 for none)
  2173.     mLabelsTextTraitsID = -1;        // -1 means standard labels style
  2174.     mSliderJustification = teFlushDefault;
  2175.     }
  2176.  
  2177. AGASliderPP::AGASliderPP(LStream* inStream)
  2178. : Inherited(inStream)
  2179.     {
  2180.     mAGAObject = NULL;
  2181.     mNotificationRoutine = NULL;
  2182.     mUserData = 0;
  2183.     mLabelsResourceID = mUserCon;    // STR# resource ID of the slider labels (0 for none)
  2184.     mLabelsTextTraitsID = -1;        // -1 means standard labels style
  2185.     mSliderJustification = teFlushDefault;
  2186.     }
  2187.  
  2188. AGASliderPP::~AGASliderPP()
  2189.     {
  2190.     // Delete AGA object if we successfully allocated it.
  2191.  
  2192.     if (mAGAObject != NULL)
  2193.         delete mAGAObject;
  2194.     }
  2195.  
  2196. void AGASliderPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  2197.     {
  2198.     // Let the PowerPlant and AGA objects update their bounds.
  2199.  
  2200.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  2201.     
  2202.     ResetAGAObjectFrame(this, mAGAObject);
  2203.     }
  2204.  
  2205. void AGASliderPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  2206.     {
  2207.     // Let the PowerPlant and AGA objects update their bounds.
  2208.  
  2209.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  2210.     
  2211.     ResetAGAObjectFrame(this, mAGAObject);
  2212.     }
  2213.  
  2214. void AGASliderPP::InstallNotificationRoutine(AGANotifyPPPtr notificationRoutine, void* userData)
  2215.     {
  2216.     // Save the notification routine fn pointer and user data
  2217.     // for notification handling.
  2218.  
  2219.     mNotificationRoutine = notificationRoutine;
  2220.     mUserData = userData;
  2221.     }
  2222.  
  2223. void AGASliderPP::HandleNotification(SInt32 dataValue)
  2224.     {
  2225.     // Update the pane value, call the installed notification
  2226.     // function, and propagate our event number.
  2227.  
  2228.     this->SetValue(dataValue);
  2229.  
  2230.     if (mNotificationRoutine != NULL)
  2231.         (*mNotificationRoutine)(this, dataValue, mUserData);
  2232.  
  2233.     this->BroadcastValueMessage();
  2234.  
  2235.     (void) this->FocusDraw();    // HandleEvent may have caused another view to draw
  2236.     }
  2237.  
  2238. void AGASliderPP::FinishCreateSelf()
  2239.     {
  2240.     // Create and set up the AGAObject.
  2241.  
  2242.     this->CreateAGAObject();
  2243.     }
  2244.  
  2245. void AGASliderPP::DrawSelf()
  2246.     {
  2247.     // Let the AGAObject draw itself.
  2248.  
  2249.     if (mAGAObject != NULL)
  2250.         mAGAObject->DrawObject();
  2251.     }
  2252.  
  2253. void AGASliderPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  2254.     {
  2255.     // Let the AGAObject track the mouse.
  2256.  
  2257.     if (mAGAObject != NULL)
  2258.         {
  2259.         this->FocusDraw();
  2260.         
  2261.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  2262.             this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
  2263.         }
  2264.     }
  2265.  
  2266. void AGASliderPP::HotSpotResult(SInt16 /*inHotSpot*/)
  2267.     {
  2268.     this->SetValue(mAGAObject->GetValue());
  2269.     }
  2270.  
  2271. void AGASliderPP::EnableSelf()
  2272.     {
  2273.     // Let the AGAObject enable itself.
  2274.  
  2275.     if (mAGAObject != NULL)
  2276.         {
  2277.         this->FocusDraw();
  2278.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  2279.         }
  2280.     }
  2281.  
  2282. void AGASliderPP::DisableSelf()
  2283.     {
  2284.     // Let the AGAObject disable itself.
  2285.  
  2286.     if (mAGAObject != NULL)
  2287.         {
  2288.         this->FocusDraw();
  2289.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  2290.         }
  2291.     }
  2292.  
  2293. void AGASliderPP::CreateAGAObject()
  2294.     {
  2295.     // Instantiate the particular AGAObject subclass.
  2296.  
  2297.     Rect    bounds;
  2298.     
  2299.     (void) this->CalcLocalFrameRect(bounds);
  2300.  
  2301.     if (mLabelsTextTraitsID == -1)
  2302.         ThrowIfNil_(mAGAObject = new AGASlider(&bounds, mMinValue, mMaxValue, mValue, gAGAStdSmallStyle, mLabelsResourceID));
  2303.     else
  2304.         ThrowIfNil_(mAGAObject = new AGASlider(&bounds, mMinValue, mMaxValue, mValue, AGATextStyle(mLabelsTextTraitsID), mLabelsResourceID));
  2305.  
  2306.     mAGAObject->InstallNotificationRoutine(AGASliderPP::RealAGANotifier, this);
  2307.  
  2308.     if (mSliderJustification != teFlushDefault)
  2309.         mAGAObject->SetJustification(mSliderJustification);
  2310.  
  2311.     if (mEnabled == triState_Off)
  2312.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2313.     
  2314.     // The auto-labeling may have increased the range. We need to
  2315.     // make sure the LControl min/max respect that, or SetValue
  2316.     // won't work.
  2317.     
  2318.     SInt32    newMin;
  2319.     SInt32    newMax;
  2320.  
  2321.     mAGAObject->GetRange(&newMin, &newMax);
  2322.     this->SetMinValue(newMin);
  2323.     this->SetMaxValue(newMax);
  2324.  
  2325.     // Slider has to erase when drawing, so make sure that
  2326.     // it doesn't assume we're on a gray background.
  2327.     
  2328.     this->FocusDraw();
  2329.     this->ApplyForeAndBackColors();
  2330.     InstallAGABackgroundColors(mAGAObject, kInstallAlways);
  2331.     }
  2332.  
  2333. void AGASliderPP::SetValue(SInt32 inValue)
  2334.     {
  2335.     // Set the slider value.
  2336.  
  2337.     Inherited::SetValue(inValue);
  2338.  
  2339.     if (mAGAObject != NULL)
  2340.         {
  2341.         this->FocusDraw();
  2342.         
  2343.         mAGAObject->SetValue(mValue, this->IsVisible());
  2344.         }
  2345.     }
  2346.  
  2347. void AGASliderPP::SetMinValue(SInt32 inMinValue)
  2348.     {
  2349.     // Set the slider min.
  2350.  
  2351.     Inherited::SetMinValue(inMinValue);
  2352.  
  2353.     if (mAGAObject != NULL)
  2354.         {
  2355.         SInt32    oldMin;
  2356.         SInt32    oldMax;
  2357.  
  2358.         this->FocusDraw();
  2359.         
  2360.         mAGAObject->GetRange(&oldMin, &oldMax);
  2361.         mAGAObject->SetRange(inMinValue, oldMax, this->IsVisible());
  2362.         }
  2363.     }
  2364.  
  2365. void AGASliderPP::SetMaxValue(SInt32 inMaxValue)
  2366.     {
  2367.     // Set the slider max.
  2368.  
  2369.     Inherited::SetMaxValue(inMaxValue);
  2370.  
  2371.     if (mAGAObject != NULL)
  2372.         {
  2373.         SInt32    oldMin;
  2374.         SInt32    oldMax;
  2375.  
  2376.         this->FocusDraw();
  2377.         
  2378.         mAGAObject->GetRange(&oldMin, &oldMax);
  2379.         mAGAObject->SetRange(oldMin, inMaxValue, this->IsVisible());
  2380.         }
  2381.     }
  2382.  
  2383. void AGASliderPP::RealAGANotifier(AGATrackingIndicator* /*theIndicator*/, SInt32 dataValue, void* userData)
  2384.     {
  2385.     // This is a static function. Cast the user data to get
  2386.     // the AGASliderPP object, have it handle the notification.
  2387.  
  2388.     ((AGASliderPP*) userData)->HandleNotification(dataValue);
  2389.     }
  2390.  
  2391. //
  2392. // AGASliderPPX ----------------------------------------------------
  2393. //
  2394.  
  2395. #undef Inherited
  2396. #define Inherited AGASliderPP
  2397.  
  2398. AGASliderPPX* AGASliderPPX::CreateStream(LStream* inStream)
  2399.     {
  2400.     return new AGASliderPPX(inStream);
  2401.     }
  2402.  
  2403. AGASliderPPX::AGASliderPPX(LStream* inStream)
  2404. : Inherited(inStream)
  2405.     {
  2406.     // Read the labels STR# ID, labels text traits ID, and
  2407.     // slider justification from the stream.
  2408.  
  2409.     inStream->ReadData(&mLabelsResourceID, sizeof(mLabelsResourceID));
  2410.     inStream->ReadData(&mLabelsTextTraitsID, sizeof(mLabelsTextTraitsID));
  2411.     inStream->ReadData(&mSliderJustification, sizeof(mSliderJustification));
  2412.     }
  2413.  
  2414. AGASliderPPX::~AGASliderPPX()
  2415.     {
  2416.     }
  2417.  
  2418. //
  2419. // AGALittleArrowsPP ----------------------------------------------------
  2420. //
  2421.  
  2422. #undef Inherited
  2423. #define Inherited LControl
  2424.  
  2425. AGALittleArrowsPP* AGALittleArrowsPP::CreateStream(LStream* inStream)
  2426.     {
  2427.     return new AGALittleArrowsPP(inStream);
  2428.     }
  2429.  
  2430. AGALittleArrowsPP::AGALittleArrowsPP()
  2431.     {
  2432.     mNotificationRoutine = NULL;
  2433.     mAGAObject = NULL;
  2434.     mLinkedNumberText = NULL;
  2435.     mLinkedPaneID = 0;
  2436.     }
  2437.  
  2438. AGALittleArrowsPP::AGALittleArrowsPP(LStream* inStream)
  2439. : Inherited(inStream)
  2440.     {
  2441.     mNotificationRoutine = NULL;
  2442.     mAGAObject = NULL;
  2443.     mLinkedNumberText = NULL;
  2444.     mLinkedPaneID = mUserCon;
  2445.     }
  2446.  
  2447. AGALittleArrowsPP::~AGALittleArrowsPP()
  2448.     {
  2449.     // Delete AGA object if we successfully allocated it.
  2450.  
  2451.     if (mAGAObject != NULL)
  2452.         delete mAGAObject;
  2453.     }
  2454.  
  2455. void AGALittleArrowsPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  2456.     {
  2457.     // Let the PowerPlant and AGA objects update their bounds.
  2458.  
  2459.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  2460.     
  2461.     ResetAGAObjectFrame(this, mAGAObject);
  2462.     }
  2463.  
  2464. void AGALittleArrowsPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  2465.     {
  2466.     // Let the PowerPlant and AGA objects update their bounds.
  2467.  
  2468.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  2469.     
  2470.     ResetAGAObjectFrame(this, mAGAObject);
  2471.     }
  2472.  
  2473. void AGALittleArrowsPP::InstallNotificationRoutine(AGANotifyPPPtr notificationRoutine, void* userData)
  2474.     {
  2475.     // Save the notification routine fn pointer and user data
  2476.     // for notification handling.
  2477.  
  2478.     mNotificationRoutine = notificationRoutine;
  2479.     mUserData = userData;
  2480.     }
  2481.  
  2482. void AGALittleArrowsPP::HandleNotification(SInt32 deltaValue)
  2483.     {
  2484.     // Update the linked LEditField, if any, call the
  2485.     // installed notification function, and propagate our
  2486.     // hot spot result.
  2487.     
  2488.     SInt32    oldValue;
  2489.     SInt32    newValue;
  2490.  
  2491.     if (mLinkedNumberText == NULL)
  2492.         oldValue = this->GetValue();
  2493.     else
  2494.         oldValue = mLinkedNumberText->GetValue();
  2495.     
  2496.     // Set the LControl value, which will constrain between min and max.
  2497.     this->SetValue(oldValue + deltaValue);
  2498.     
  2499.     // Get the new value, which may be been constrained.
  2500.     newValue = this->GetValue();
  2501.     
  2502.     // Only set new linked text value if changed.
  2503.     if ((mLinkedNumberText != NULL) && (newValue != oldValue))
  2504.         {
  2505.         mLinkedNumberText->SetValue(newValue);
  2506.         mLinkedNumberText->Draw(NULL);
  2507.         mLinkedNumberText->DontRefresh();    // otherwise attachments will flicker after mouse tracking completes
  2508.         }
  2509.  
  2510.     if (mNotificationRoutine != NULL)
  2511.         (*mNotificationRoutine)(this, deltaValue, mUserData);
  2512.     
  2513.     this->FocusDraw();    // linked edit field prob'ly grabbed focus
  2514.     }
  2515.  
  2516. void AGALittleArrowsPP::FinishCreateSelf()
  2517.     {
  2518.     // Create and set up the AGAObject.
  2519.  
  2520.     this->CreateAGAObject();
  2521.     }
  2522.  
  2523. void AGALittleArrowsPP::DrawSelf()
  2524.     {
  2525.     // Let the AGAObject draw itself.
  2526.  
  2527.     if (mAGAObject != NULL)
  2528.         mAGAObject->DrawObject();
  2529.     }
  2530.  
  2531. void AGALittleArrowsPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  2532.     {
  2533.     // Let the AGAObject track the mouse.
  2534.  
  2535.     if (mAGAObject != NULL)
  2536.         {
  2537.         this->FocusDraw();
  2538.         
  2539.         // Note that we don't do anything after tracking; the
  2540.         // notification routine updates the value continuously
  2541.         // while tracking occurs.
  2542.         (void) mAGAObject->TrackMouse(inMouseDown.whereLocal);
  2543.         }
  2544.     }
  2545.  
  2546. void AGALittleArrowsPP::EnableSelf()
  2547.     {
  2548.     // Let the AGAObject enable itself.
  2549.  
  2550.     if (mAGAObject != NULL)
  2551.         {
  2552.         this->FocusDraw();
  2553.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  2554.         }
  2555.     }
  2556.  
  2557. void AGALittleArrowsPP::DisableSelf()
  2558.     {
  2559.     // Let the AGAObject disable itself.
  2560.  
  2561.     if (mAGAObject != NULL)
  2562.         {
  2563.         this->FocusDraw();
  2564.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  2565.         }
  2566.     }
  2567.  
  2568. void AGALittleArrowsPP::CreateAGAObject()
  2569.     {
  2570.     // Instantiate the particular AGAObject subclass.
  2571.  
  2572.     Rect    bounds;
  2573.     
  2574.     (void) this->CalcLocalFrameRect(bounds);
  2575.  
  2576.     ThrowIfNil_(mAGAObject = new AGALittleArrows(&bounds));
  2577.     
  2578.     mAGAObject->InstallNotificationRoutine(AGALittleArrowsPP::RealAGANotifier, this);
  2579.  
  2580.     if (mEnabled == triState_Off)
  2581.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2582.  
  2583.     if (mLinkedPaneID != 0)
  2584.         {
  2585.         // If you bypass the RTTI here, you must ensure that the
  2586.         // pane ID specifies a pane that is a subclass of LEditField.
  2587.         
  2588.         LPane*    linkedPane = mSuperView->FindPaneByID(mLinkedPaneID);
  2589.         
  2590.         if (linkedPane != NULL)
  2591.             {
  2592. #ifndef NO_RTTI
  2593.             mLinkedNumberText = dynamic_cast<LEditField*>(linkedPane);
  2594. #else // NO_RTTI
  2595.             mLinkedNumberText = (LEditField*) linkedPane;
  2596. #endif // NO_RTTI
  2597.  
  2598.             if (mLinkedNumberText != NULL)
  2599.                 mLinkedNumberText->SetValue(mValue);
  2600.             }
  2601.         }
  2602.     }
  2603.  
  2604. void AGALittleArrowsPP::RealAGANotifier(AGALittleArrows* /*theAGAObject*/, SInt32 deltaValue, void* userData)
  2605.     {
  2606.     // This is a static function. Cast the user data to get
  2607.     // the AGAScrollerScrollBarMA object, have it handle the notification.
  2608.  
  2609.     ((AGALittleArrowsPP*) userData)->HandleNotification(deltaValue);
  2610.     }
  2611.  
  2612. //
  2613. // AGALittleArrowsPPX ----------------------------------------------------
  2614. //
  2615.  
  2616. #undef Inherited
  2617. #define Inherited AGALittleArrowsPP
  2618.  
  2619. AGALittleArrowsPPX* AGALittleArrowsPPX::CreateStream(LStream* inStream)
  2620.     {
  2621.     return new AGALittleArrowsPPX(inStream);
  2622.     }
  2623.  
  2624. AGALittleArrowsPPX::AGALittleArrowsPPX(LStream* inStream)
  2625. : Inherited(inStream)
  2626.     {
  2627.     // Read the linked LEditField pane ID from the stream.
  2628.  
  2629.     inStream->ReadData(&mLinkedPaneID, sizeof(mLinkedPaneID));
  2630.     }
  2631.  
  2632. AGALittleArrowsPPX::~AGALittleArrowsPPX()
  2633.     {
  2634.     }
  2635.  
  2636. //
  2637. // AGAPopupMenuPP ----------------------------------------------------
  2638. //
  2639.  
  2640. #undef Inherited
  2641. #define Inherited LStdPopupMenu
  2642.  
  2643. AGAPopupMenuPP* AGAPopupMenuPP::CreateStream(LStream* inStream)
  2644.     {
  2645.     return new AGAPopupMenuPP(inStream);
  2646.     }
  2647.  
  2648. AGAPopupMenuPP::AGAPopupMenuPP(LStream* inStream)
  2649. : Inherited(inStream)
  2650.     {
  2651.     mAGAObject = NULL;
  2652.     
  2653.     // When creating the core AGA object, we will need to know
  2654.     // the title width and title variation of the popup menu.
  2655.     // Unfortunately, due to the hack nature of the CDEF and the
  2656.     // design peculiarities of LStdPopupMenu, we have no way to
  2657.     // access those values. The only solution is to back up in
  2658.     // the PPob stream and stash them aside until needed.
  2659.     
  2660.     SInt32    originalMarker = inStream->GetMarker();
  2661.     
  2662.     // Undo the LStdPopupMenu stream read.
  2663.     inStream->SetMarker(-sizeof(Int16), streamFrom_Marker);
  2664.     
  2665.     // Undo the LStdControl stream read.
  2666.     inStream->SetMarker(-sizeof(Int16), streamFrom_Marker);
  2667.     inStream->SetMarker(-sizeof(ResIDT), streamFrom_Marker);
  2668.     inStream->SetMarker(-sizeof(Int32), streamFrom_Marker);
  2669.     Str255    title;
  2670.     ::GetControlTitle(mMacControlH, title);
  2671.     inStream->SetMarker(-1 -title[0], streamFrom_Marker);
  2672.     
  2673.     // Undo the LControl stream read.
  2674.     inStream->SetMarker(-sizeof(SControlInfo), streamFrom_Marker);
  2675.     
  2676.     // Finally, re-read the LControl pane data.
  2677.     SControlInfo    controlInfo;
  2678.     inStream->ReadData(&controlInfo, sizeof(SControlInfo));
  2679.  
  2680.     mStashedTitleVariation = controlInfo.value;    // popup CDEF uses ctl value for other stuff
  2681.     mStashedTitleWidth = controlInfo.maxValue;    // popup CDEF uses ctl max for width
  2682.     
  2683.     // And skip forward in the stream so it's back where it
  2684.     // was before we touched it, in case a subclass is reading it.
  2685.     inStream->SetMarker(originalMarker, streamFrom_Start);
  2686.     }
  2687.  
  2688. AGAPopupMenuPP::~AGAPopupMenuPP()
  2689.     {
  2690.     // Delete AGA object if we successfully allocated it.
  2691.  
  2692.     if (mAGAObject != NULL)
  2693.         delete mAGAObject;
  2694.     }
  2695.  
  2696. void AGAPopupMenuPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  2697.     {
  2698.     // Let the PowerPlant and AGA objects update their bounds.
  2699.  
  2700.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  2701.     
  2702.     ResetAGAObjectFrame(this, mAGAObject);
  2703.     }
  2704.  
  2705. void AGAPopupMenuPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  2706.     {
  2707.     // Let the PowerPlant and AGA objects update their bounds.
  2708.  
  2709.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  2710.     
  2711.     ResetAGAObjectFrame(this, mAGAObject);
  2712.     }
  2713.  
  2714. void AGAPopupMenuPP::FinishCreateSelf()
  2715.     {
  2716.     // Create and set up the AGAObject.
  2717.  
  2718.     this->HideSelf();    // make sure the Control Manager object is not drawn
  2719.     
  2720.     this->CreateAGAObject();
  2721.     }
  2722.  
  2723. void AGAPopupMenuPP::DrawSelf()
  2724.     {
  2725.     // Let the AGAObject draw itself.
  2726.  
  2727.     if (mAGAObject != NULL)
  2728.         mAGAObject->DrawObject();
  2729.     }
  2730.  
  2731. void AGAPopupMenuPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  2732.     {
  2733.     // Let the AGAObject track the mouse.
  2734.  
  2735.     if (mAGAObject != NULL)
  2736.         {
  2737.         this->FocusDraw();
  2738.         
  2739.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  2740.             this->SetValue(mAGAObject->GetCurrentItemNo());
  2741.         }
  2742.     }
  2743.  
  2744. void AGAPopupMenuPP::EnableSelf()
  2745.     {
  2746.     // Let the AGAObject enable itself.
  2747.  
  2748.     if (mAGAObject != NULL)
  2749.         {
  2750.         this->FocusDraw();
  2751.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  2752.         }
  2753.     }
  2754.  
  2755. void AGAPopupMenuPP::DisableSelf()
  2756.     {
  2757.     // Let the AGAObject disable itself.
  2758.  
  2759.     if (mAGAObject != NULL)
  2760.         {
  2761.         this->FocusDraw();
  2762.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  2763.         }
  2764.     }
  2765.  
  2766. void AGAPopupMenuPP::ShowSelf()
  2767.     {
  2768.     // Suppress showing the Control Manager control.
  2769.     }
  2770.  
  2771. void AGAPopupMenuPP::CreateAGAObject()
  2772.     {
  2773.     // Instantiate the particular AGAObject subclass.
  2774.  
  2775.     AGAPopupMenu::WidthAdjust    widthAdjust;
  2776.  
  2777.     Rect            bounds;
  2778.     Str255            title;
  2779.     MenuRef            theMenuRef = this->GetMacMenuH();
  2780.     SInt8            titleJustification = mStashedTitleVariation & 0xFF;
  2781.     AGATextStyle    titleStyle(mTextTraitsID);
  2782.     
  2783.     if (((mControlKind - popupMenuProc) & popupFixedWidth) != 0)
  2784.         widthAdjust = AGAPopupMenu::kFixedWidth;
  2785.     else
  2786.         widthAdjust = AGAPopupMenu::kSystemMDEFAdjustment;
  2787.     
  2788.     (void) this->CalcLocalFrameRect(bounds);
  2789.     ::GetControlTitle(mMacControlH, title);
  2790.     
  2791.     // Look at the wacky popup CDEF title style bits.
  2792.     titleStyle.mFontStyle = 0;    // init to plain text
  2793.     if ((mStashedTitleVariation & popupTitleBold) != 0)
  2794.         titleStyle.mFontStyle |= bold;
  2795.     if ((mStashedTitleVariation & popupTitleItalic) != 0)
  2796.         titleStyle.mFontStyle |= italic;
  2797.     if ((mStashedTitleVariation & popupTitleUnderline) != 0)
  2798.         titleStyle.mFontStyle |= underline;
  2799.     if ((mStashedTitleVariation & popupTitleOutline) != 0)
  2800.         titleStyle.mFontStyle |= outline;
  2801.     if ((mStashedTitleVariation & popupTitleShadow) != 0)
  2802.         titleStyle.mFontStyle |= shadow;
  2803.     if ((mStashedTitleVariation & popupTitleCondense) != 0)
  2804.         titleStyle.mFontStyle |= condense;
  2805.     if ((mStashedTitleVariation & popupTitleExtend) != 0)
  2806.         titleStyle.mFontStyle |= extend;
  2807.  
  2808.     ThrowIfNil_(mAGAObject = new AGAPopupMenu(&bounds, mStashedTitleWidth, title, titleJustification, titleStyle, AGATextStyle(mTextTraitsID), widthAdjust, this->GetMacMenuH(), AGAPopupMenu::kDontDispose));
  2809.  
  2810.     mAGAObject->SetCurrentItemNo(mValue, AGAObject::kDontRedraw);
  2811.  
  2812.     if (mEnabled == triState_Off)
  2813.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2814.     }
  2815.  
  2816. void AGAPopupMenuPP::SetValue(SInt32 inValue)
  2817.     {
  2818.     // Set the actual LStdControl value and the AGA object value.
  2819.  
  2820.     Inherited::SetValue(inValue);
  2821.  
  2822.     if (mAGAObject != NULL)
  2823.         {
  2824.         this->FocusDraw();
  2825.         mAGAObject->SetCurrentItemNo(mValue, this->IsVisible());
  2826.         }
  2827.     }
  2828.  
  2829. //
  2830. // AGADisclosureTrianglePP ----------------------------------------------------
  2831. //
  2832.  
  2833. #undef Inherited
  2834. #define Inherited LControl
  2835.  
  2836. AGADisclosureTrianglePP* AGADisclosureTrianglePP::CreateStream(LStream* inStream)
  2837.     {
  2838.     return new AGADisclosureTrianglePP(inStream);
  2839.     }
  2840.  
  2841. AGADisclosureTrianglePP::AGADisclosureTrianglePP()
  2842.     {
  2843.     mAGAObject = NULL;
  2844.     mMaxValue = 1;    // make sure SetValue doesn't get stuck at value = 0
  2845.     }
  2846.  
  2847. AGADisclosureTrianglePP::AGADisclosureTrianglePP(LStream* inStream)
  2848. : Inherited(inStream)
  2849.     {
  2850.     mAGAObject = NULL;
  2851.     mMaxValue = 1;    // make sure SetValue doesn't get stuck at value = 0
  2852.     }
  2853.  
  2854. AGADisclosureTrianglePP::~AGADisclosureTrianglePP()
  2855.     {
  2856.     // Delete AGA object if we successfully allocated it.
  2857.  
  2858.     if (mAGAObject != NULL)
  2859.         delete mAGAObject;
  2860.     }
  2861.  
  2862. void AGADisclosureTrianglePP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  2863.     {
  2864.     // Let the PowerPlant and AGA objects update their bounds.
  2865.  
  2866.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  2867.     
  2868.     ResetAGAObjectFrame(this, mAGAObject);
  2869.     }
  2870.  
  2871. void AGADisclosureTrianglePP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  2872.     {
  2873.     // Let the PowerPlant and AGA objects update their bounds.
  2874.  
  2875.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  2876.     
  2877.     ResetAGAObjectFrame(this, mAGAObject);
  2878.     }
  2879.  
  2880. void AGADisclosureTrianglePP::FinishCreateSelf()
  2881.     {
  2882.     // Create and set up the AGAObject.
  2883.  
  2884.     this->CreateAGAObject();
  2885.     }
  2886.  
  2887. void AGADisclosureTrianglePP::DrawSelf()
  2888.     {
  2889.     // Let the AGAObject draw itself.
  2890.  
  2891.     if (mAGAObject != NULL)
  2892.         mAGAObject->DrawObject();
  2893.     }
  2894.  
  2895. void AGADisclosureTrianglePP::ClickSelf(const SMouseDownEvent &inMouseDown)
  2896.     {
  2897.     // Let the AGAObject track the mouse.
  2898.  
  2899.     if (mAGAObject != NULL)
  2900.         {
  2901.         this->FocusDraw();
  2902.         
  2903.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  2904.             this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
  2905.         }
  2906.     }
  2907.  
  2908. void AGADisclosureTrianglePP::HotSpotResult(SInt16 /*inHotSpot*/)
  2909.     {
  2910.     this->SetValue(mAGAObject->GetState() ? 1 : 0);
  2911.     }
  2912.  
  2913. void AGADisclosureTrianglePP::EnableSelf()
  2914.     {
  2915.     // Let the AGAObject enable itself.
  2916.  
  2917.     if (mAGAObject != NULL)
  2918.         {
  2919.         this->FocusDraw();
  2920.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  2921.         }
  2922.     }
  2923.  
  2924. void AGADisclosureTrianglePP::DisableSelf()
  2925.     {
  2926.     // Let the AGAObject disable itself.
  2927.  
  2928.     if (mAGAObject != NULL)
  2929.         {
  2930.         this->FocusDraw();
  2931.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  2932.         }
  2933.     }
  2934.  
  2935. void AGADisclosureTrianglePP::CreateAGAObject()
  2936.     {
  2937.     // Instantiate the particular AGAObject subclass.
  2938.     
  2939.     Rect    bounds;
  2940.     
  2941.     (void) this->CalcLocalFrameRect(bounds);
  2942.  
  2943.     ThrowIfNil_(mAGAObject = new AGADisclosureTriangle(&bounds, AGAObject::kAutomaticState));
  2944.     
  2945.     if (mEnabled == triState_Off)
  2946.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2947.  
  2948.     if (mValue != 0)    // allow initial state to be set to kDisclosed
  2949.         mAGAObject->SetState(AGADisclosureTriangle::kDisclosedState, AGAObject::kDontRedraw);
  2950.  
  2951.     // Disclosure triangle has to erase when animating, so make sure that
  2952.     // it doesn't assume we're on a gray background.
  2953.  
  2954.     this->FocusDraw();
  2955.     this->ApplyForeAndBackColors();
  2956.     InstallAGABackgroundColors(mAGAObject, kInstallAlways);
  2957.     }
  2958.  
  2959. void AGADisclosureTrianglePP::SetValue(SInt32 inValue)
  2960.     {
  2961.     // Set the actual LControl value and the AGA object state.
  2962.  
  2963.     Inherited::SetValue(inValue);
  2964.  
  2965.     if (mAGAObject != NULL)
  2966.         {
  2967.         this->FocusDraw();
  2968.         mAGAObject->SetState(mValue != 0, this->IsVisible());
  2969.         }
  2970.     }
  2971.  
  2972. //
  2973. // AGAProgressIndicatorPP ----------------------------------------------------
  2974. //
  2975.  
  2976. #undef Inherited
  2977. #define Inherited LControl
  2978.  
  2979. AGAProgressIndicatorPP* AGAProgressIndicatorPP::CreateStream(LStream* inStream)
  2980.     {
  2981.     return new AGAProgressIndicatorPP(inStream);
  2982.     }
  2983.  
  2984. AGAProgressIndicatorPP::AGAProgressIndicatorPP()
  2985.     {
  2986.     mAGAObject = NULL;
  2987.     }
  2988.  
  2989. AGAProgressIndicatorPP::AGAProgressIndicatorPP(LStream* inStream)
  2990. : Inherited(inStream)
  2991.     {
  2992.     mAGAObject = NULL;
  2993.     }
  2994.  
  2995. AGAProgressIndicatorPP::~AGAProgressIndicatorPP()
  2996.     {
  2997.     // Delete AGA object if we successfully allocated it.
  2998.  
  2999.     if (mAGAObject != NULL)
  3000.         delete mAGAObject;
  3001.     }
  3002.  
  3003. void AGAProgressIndicatorPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  3004.     {
  3005.     // Let the PowerPlant and AGA objects update their bounds.
  3006.  
  3007.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  3008.     
  3009.     ResetAGAObjectFrame(this, mAGAObject);
  3010.     }
  3011.  
  3012. void AGAProgressIndicatorPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  3013.     {
  3014.     // Let the PowerPlant and AGA objects update their bounds.
  3015.  
  3016.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  3017.     
  3018.     ResetAGAObjectFrame(this, mAGAObject);
  3019.     }
  3020.  
  3021. void AGAProgressIndicatorPP::FinishCreateSelf()
  3022.     {
  3023.     // Create and set up the AGAObject.
  3024.  
  3025.     this->CreateAGAObject();
  3026.     }
  3027.  
  3028. void AGAProgressIndicatorPP::DrawSelf()
  3029.     {
  3030.     // Let the AGAObject draw itself.
  3031.  
  3032.     if (mAGAObject != NULL)
  3033.         mAGAObject->DrawObject();
  3034.     }
  3035.  
  3036. void AGAProgressIndicatorPP::CreateAGAObject()
  3037.     {
  3038.     // Instantiate the particular AGAObject subclass.
  3039.     
  3040.     Rect    bounds;
  3041.     
  3042.     (void) this->CalcLocalFrameRect(bounds);
  3043.  
  3044.     ThrowIfNil_(mAGAObject = new AGAProgressIndicator(&bounds, mMinValue, mMaxValue));
  3045.     
  3046.     mAGAObject->SetValue(mValue, AGAObject::kDontRedraw);
  3047.     
  3048.     if (mUserCon != 0)
  3049.         this->StartAutoAnimate();
  3050.     }
  3051.  
  3052. void AGAProgressIndicatorPP::SetValue(SInt32 inValue)
  3053.     {
  3054.     // Set the value of the LControl and the AGA object.
  3055.  
  3056.     Inherited::SetValue(inValue);
  3057.  
  3058.     if (mAGAObject != NULL)
  3059.         {
  3060.         this->FocusDraw();
  3061.         
  3062.         mAGAObject->SetValue(mValue, this->IsVisible());
  3063.         }
  3064.     }
  3065.  
  3066. void AGAProgressIndicatorPP::SetMinValue(SInt32 inMinValue)
  3067.     {
  3068.     // Set the min of the LControl and the AGA object.
  3069.  
  3070.     Inherited::SetMinValue(inMinValue);
  3071.  
  3072.     if (mAGAObject != NULL)
  3073.         {
  3074.         SInt32    oldMin;
  3075.         SInt32    oldMax;
  3076.  
  3077.         this->FocusDraw();
  3078.         
  3079.         mAGAObject->GetRange(&oldMin, &oldMax);
  3080.         mAGAObject->SetRange(inMinValue, oldMax, this->IsVisible());
  3081.         }
  3082.     }
  3083.  
  3084. void AGAProgressIndicatorPP::SetMaxValue(SInt32 inMaxValue)
  3085.     {
  3086.     // Set the max of the LControl and the AGA object.
  3087.  
  3088.     Inherited::SetMaxValue(inMaxValue);
  3089.  
  3090.     if (mAGAObject != NULL)
  3091.         {
  3092.         SInt32    oldMin;
  3093.         SInt32    oldMax;
  3094.  
  3095.         this->FocusDraw();
  3096.         
  3097.         mAGAObject->GetRange(&oldMin, &oldMax);
  3098.         mAGAObject->SetRange(oldMin, inMaxValue, this->IsVisible());
  3099.         }
  3100.     }
  3101.  
  3102. void AGAProgressIndicatorPP::SpendTime(const EventRecord& /*inMacEvent*/)
  3103.     {
  3104.     // Let the AGAObject do one animation step.
  3105.  
  3106.     if (mAGAObject != NULL)
  3107.         {
  3108.         this->FocusDraw();
  3109.         mAGAObject->QuantizedAnimate();
  3110.         }
  3111.     }
  3112.  
  3113. void AGAProgressIndicatorPP::StartAutoAnimate()
  3114.     {
  3115.     // Let LPeriodical remove us from its idle queue.
  3116.     
  3117.     this->StartIdling();
  3118.     }
  3119.  
  3120. void AGAProgressIndicatorPP::StopAutoAnimate()
  3121.     {
  3122.     // Tell LPeriodical to add us to its idle queue.
  3123.     
  3124.     this->StopIdling();
  3125.     }
  3126.  
  3127. //
  3128. // AGAWhiteBackgroundAttachmentPP ----------------------------------------------------
  3129. //
  3130.  
  3131. #undef Inherited
  3132. #define Inherited LAttachment
  3133.  
  3134. AGAWhiteBackgroundAttachmentPP* AGAWhiteBackgroundAttachmentPP::CreateStream(LStream* inStream)
  3135.     {
  3136.     return new AGAWhiteBackgroundAttachmentPP(inStream);
  3137.     }
  3138.  
  3139. AGAWhiteBackgroundAttachmentPP::AGAWhiteBackgroundAttachmentPP(MessageT inMessage, Boolean inExecuteHost)
  3140. : Inherited(inMessage, inExecuteHost)
  3141.     {
  3142.     mIsNotched = false;
  3143.     }
  3144.  
  3145. AGAWhiteBackgroundAttachmentPP::AGAWhiteBackgroundAttachmentPP(LStream *inStream)
  3146. : Inherited(inStream)
  3147.     {
  3148.     mIsNotched = false;
  3149.     }
  3150.  
  3151. Boolean AGAWhiteBackgroundAttachmentPP::Execute(MessageT inMessage, void *ioParam)
  3152.     {
  3153.     if (inMessage == msg_DrawOrPrint)
  3154.         {
  3155.         AGADrawingEnvironment    env;
  3156.  
  3157.         // Draw the background in white, inset to avoid the border
  3158.         // frame pixels.
  3159.  
  3160.         Rect    paneFrame = *((Rect*) ioParam);
  3161.         
  3162.         ::RGBForeColor(&gAGARamp[rW]);
  3163.         ::InsetRect(&paneFrame, 1, 1);
  3164.         
  3165.         if (mIsNotched)
  3166.             {
  3167.             Rect    r;
  3168.             
  3169.             r = paneFrame;
  3170.             r.right -= 15;
  3171.             ::PaintRect(&r);
  3172.             
  3173.             r = paneFrame;
  3174.             r.bottom -= 15;
  3175.             ::PaintRect(&r);
  3176.             }
  3177.         else
  3178.             {
  3179.             ::PaintRect(&paneFrame);
  3180.             }
  3181.         }
  3182.     
  3183.     return true;    // owner should also do its work
  3184.     }
  3185.  
  3186. //
  3187. // AGANotchedWhiteBackgroundAttachmentPP ----------------------------------------------------
  3188. //
  3189.  
  3190. #undef Inherited
  3191. #define Inherited AGAWhiteBackgroundAttachmentPP
  3192.  
  3193. AGANotchedWhiteBackgroundAttachmentPP* AGANotchedWhiteBackgroundAttachmentPP::CreateStream(LStream* inStream)
  3194.     {
  3195.     return new AGANotchedWhiteBackgroundAttachmentPP(inStream);
  3196.     }
  3197.  
  3198. AGANotchedWhiteBackgroundAttachmentPP::AGANotchedWhiteBackgroundAttachmentPP(MessageT inMessage, Boolean inExecuteHost)
  3199. : Inherited(inMessage, inExecuteHost)
  3200.     {
  3201.     mIsNotched = true;
  3202.     }
  3203.  
  3204. AGANotchedWhiteBackgroundAttachmentPP::AGANotchedWhiteBackgroundAttachmentPP(LStream *inStream)
  3205. : Inherited(inStream)
  3206.     {
  3207.     mIsNotched = true;
  3208.     }
  3209.  
  3210. //
  3211. // AGABorderFrameAttachmentPP ----------------------------------------------------
  3212. //
  3213.  
  3214. #undef Inherited
  3215. #define Inherited LAttachment
  3216.  
  3217. AGABorderFrameAttachmentPP* AGABorderFrameAttachmentPP::CreateStream(LStream* inStream)
  3218.     {
  3219.     return new AGABorderFrameAttachmentPP(inStream);
  3220.     }
  3221.  
  3222. AGABorderFrameAttachmentPP::AGABorderFrameAttachmentPP(MessageT inMessage, Boolean inExecuteHost)
  3223. : Inherited(inMessage, inExecuteHost)
  3224.     {
  3225.     mIsNotched = false;
  3226.     }
  3227.  
  3228. AGABorderFrameAttachmentPP::AGABorderFrameAttachmentPP(LStream *inStream)
  3229. : Inherited(inStream)
  3230.     {
  3231.     mIsNotched = false;
  3232.     }
  3233.  
  3234. Boolean AGABorderFrameAttachmentPP::Execute(MessageT inMessage, void *ioParam)
  3235.     {
  3236.     if (inMessage == msg_DrawOrPrint)
  3237.         {
  3238.         AGADrawingEnvironment    env;
  3239.  
  3240.         // Draw the frame with shading outside.
  3241.  
  3242.         // If you bypass the RTTI here, the frame will always
  3243.         // draw enabled. With the 7/96 AGA spec revision, this
  3244.         // is now visually obvious.
  3245.         
  3246.         Boolean    ownerEnabled = true;
  3247.         
  3248. #ifndef NO_RTTI
  3249.         LPane*    ownerPane = dynamic_cast<LPane*>(mOwnerHost);
  3250.         if (ownerPane != NULL)
  3251.             ownerEnabled = ownerPane->IsEnabled();
  3252. #endif // NO_RTTI
  3253.  
  3254.         // The sunken border is drawn in the pixel outside the
  3255.         // pane frame.
  3256.  
  3257.         Rect    paneFrame = *((Rect*) ioParam);
  3258.         
  3259.         ::InsetRect(&paneFrame, -1, -1);
  3260.         AGADrawBorderFrame(&paneFrame, ownerEnabled, mIsNotched, true /*drawFrame*/, &gAGARamp[r2]);
  3261.         }
  3262.  
  3263.     return true;    // owner should also do its work
  3264.     }
  3265.  
  3266. //
  3267. // AGANotchedBorderFrameAttachmentPP ----------------------------------------------------
  3268. //
  3269.  
  3270. #undef Inherited
  3271. #define Inherited AGABorderFrameAttachmentPP
  3272.  
  3273. AGANotchedBorderFrameAttachmentPP* AGANotchedBorderFrameAttachmentPP::CreateStream(LStream* inStream)
  3274.     {
  3275.     return new AGANotchedBorderFrameAttachmentPP(inStream);
  3276.     }
  3277.  
  3278. AGANotchedBorderFrameAttachmentPP::AGANotchedBorderFrameAttachmentPP(MessageT inMessage, Boolean inExecuteHost)
  3279. : Inherited(inMessage, inExecuteHost)
  3280.     {
  3281.     mIsNotched = true;
  3282.     }
  3283.  
  3284. AGANotchedBorderFrameAttachmentPP::AGANotchedBorderFrameAttachmentPP(LStream *inStream)
  3285. : Inherited(inStream)
  3286.     {
  3287.     mIsNotched = true;
  3288.     }
  3289.  
  3290. //
  3291. // AGAEditFieldPP ----------------------------------------------------
  3292. //
  3293.  
  3294. #undef Inherited
  3295. #define Inherited LEditField
  3296.  
  3297. AGAEditFieldPP* AGAEditFieldPP::CreateStream(LStream* inStream)
  3298.     {
  3299.     return new AGAEditFieldPP(inStream);
  3300.     }
  3301.  
  3302. AGAEditFieldPP::AGAEditFieldPP()
  3303.     {
  3304.     }
  3305.  
  3306. AGAEditFieldPP::AGAEditFieldPP(LStream* inStream)
  3307. : Inherited(inStream)
  3308.     {
  3309.     }
  3310.  
  3311. AGAEditFieldPP::~AGAEditFieldPP()
  3312.     {
  3313.     }
  3314.  
  3315. void AGAEditFieldPP::DrawSelf()
  3316.     {
  3317.     this->DrawEverything();
  3318.     }
  3319.  
  3320. void AGAEditFieldPP::DrawBox()
  3321.     {
  3322.     this->DrawEverything();
  3323.     }
  3324.  
  3325. void AGAEditFieldPP::DrawEverything()
  3326.     {
  3327.     // LEditField just isn't set up to handle our situations where dimming
  3328.     // and background color changes affect the whole view. It tries to
  3329.     // optimize by only drawing the box upon enable/disable messages. But
  3330.     // our background may change or get painted when that happens. So we catch
  3331.     // the DrawSelf and separate DrawBox messages, and just draw it all.
  3332.     
  3333.     Rect        r;
  3334.     RGBColor    textForeColor;
  3335.     RGBColor    textBackColor;
  3336.     Boolean        enabled = (mEnabled == triState_On);
  3337.     
  3338.     (void) this->CalcLocalFrameRect(r);
  3339.     
  3340.     AGADrawingEnvironment    env;
  3341.     
  3342.     ::GetForeColor(&textForeColor);
  3343.     ::GetBackColor(&textBackColor);
  3344.     ::RGBForeColor(&textBackColor);
  3345.  
  3346.     ::InsetRect(&r, 1, 1);
  3347.     ::PaintRect(&r);
  3348.     ::InsetRect(&r, -1, -1);
  3349.     
  3350.     if (mHasBox)
  3351.         {
  3352.         // Note that we just use r2 with AGADrawBorderFrame, because even
  3353.         // with tab panels, r2 is the correct disabled background color.
  3354.  
  3355.         ::InsetRect(&r, -1, -1);
  3356.         AGADrawBorderFrame(&r, enabled, false /*isNotched*/, true /*drawFrame*/, &gAGARamp[r2]);
  3357.         ::InsetRect(&r, 3, 3);
  3358.         }
  3359.     
  3360.     // Get the text to draw, just as in LEditField::DrawSelf.
  3361.     // Except we draw gray text if dimmed.
  3362.     
  3363.     if (enabled)
  3364.         ::RGBForeColor(&textForeColor);
  3365.     else
  3366.         ::RGBForeColor(&gAGARamp[r7]);
  3367.  
  3368.     GrafPtr    savePort = (**mTextEditH).inPort;
  3369.     (**mTextEditH).inPort = UQDGlobals::GetCurrentPort();
  3370.  
  3371.     ::TEUpdate(&r, mTextEditH);
  3372.     
  3373.     (**mTextEditH).inPort = savePort;
  3374.     
  3375.     // For any non-deep screens, we paint a gray pattern on
  3376.     // to the text if it's dim.
  3377.     
  3378.     if (! enabled)
  3379.         {
  3380.         GDIterator    iter;
  3381.         Boolean        deep;
  3382.  
  3383.         ::PenPat(&qd.gray);
  3384.         ::PenMode(patBic);
  3385.  
  3386.         while (iter.More(deep))
  3387.             if (! deep)
  3388.                 ::PaintRect(&r);
  3389.         }
  3390.     }
  3391.  
  3392. //
  3393. // AGATextEditPP ----------------------------------------------------
  3394. //
  3395.  
  3396. #undef Inherited
  3397. #define Inherited LTextEdit
  3398.  
  3399. AGATextEditPP* AGATextEditPP::CreateStream(LStream* inStream)
  3400.     {
  3401.     return new AGATextEditPP(inStream);
  3402.     }
  3403.  
  3404. AGATextEditPP::AGATextEditPP()
  3405.     {
  3406.     }
  3407.  
  3408. AGATextEditPP::AGATextEditPP(LStream* inStream)
  3409. : Inherited(inStream)
  3410.     {
  3411.     }
  3412.  
  3413. AGATextEditPP::~AGATextEditPP()
  3414.     {
  3415.     }
  3416.  
  3417. void AGATextEditPP::DrawSelf()
  3418.     {
  3419.     // LTextEdit clipping prevents simple attachments from doing the job.
  3420.     // So we draw the border frame ourself and make sure there's an extra
  3421.     // pixel of white around the raw TE rect.
  3422.     
  3423.     Rect        r;
  3424.     RGBColor    textForeColor;
  3425.     RGBColor    textBackColor;
  3426.     Boolean        enabled = (mEnabled == triState_On);
  3427.     
  3428.     (void) this->CalcLocalFrameRect(r);
  3429.     
  3430.     {    // wrap drawing environment in its own scope
  3431.     AGADrawingEnvironment    env;
  3432.     
  3433.     RgnHandle    savedClipping = ::NewRgn();
  3434.     
  3435.     ::GetClip(savedClipping);
  3436.     ::InsetRect(&r, -3, -3);
  3437.     ::ClipRect(&r);
  3438.  
  3439.     ::GetForeColor(&textForeColor);
  3440.     ::GetBackColor(&textBackColor);
  3441.     ::RGBForeColor(&textBackColor);
  3442.  
  3443.     AGADrawBorderFrame(&r, enabled, false /*isNotched*/, true /*drawFrame*/, &gAGARamp[r2]);
  3444.  
  3445.     ::InsetRect(&r, 2, 2);
  3446.     ::PaintRect(&r);
  3447.  
  3448.     ::SetClip(savedClipping);
  3449.     }
  3450.  
  3451.     Inherited::DrawSelf();
  3452.     }
  3453.  
  3454. //
  3455. // AGASeparatorPP ----------------------------------------------------
  3456. //
  3457.  
  3458. #undef Inherited
  3459. #define Inherited LPane
  3460.  
  3461. AGASeparatorPP* AGASeparatorPP::CreateStream(LStream* inStream)
  3462.     {
  3463.     return new AGASeparatorPP(inStream);
  3464.     }
  3465.  
  3466. AGASeparatorPP::AGASeparatorPP()
  3467.     {
  3468.     mAGAObject = NULL;
  3469.     }
  3470.  
  3471. AGASeparatorPP::AGASeparatorPP(LStream* inStream)
  3472. : Inherited(inStream)
  3473.     {
  3474.     mAGAObject = NULL;
  3475.     }
  3476.  
  3477. AGASeparatorPP::~AGASeparatorPP()
  3478.     {
  3479.     // Delete AGA object if we successfully allocated it.
  3480.  
  3481.     if (mAGAObject != NULL)
  3482.         delete mAGAObject;
  3483.     }
  3484.  
  3485. void AGASeparatorPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  3486.     {
  3487.     // Let the PowerPlant and AGA objects update their bounds.
  3488.  
  3489.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  3490.     
  3491.     ResetAGAObjectFrame(this, mAGAObject);
  3492.     }
  3493.  
  3494. void AGASeparatorPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  3495.     {
  3496.     // Let the PowerPlant and AGA objects update their bounds.
  3497.  
  3498.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  3499.     
  3500.     ResetAGAObjectFrame(this, mAGAObject);
  3501.     }
  3502.  
  3503. void AGASeparatorPP::FinishCreateSelf()
  3504.     {
  3505.     // Create and set up the AGAObject.
  3506.  
  3507.     this->CreateAGAObject();
  3508.     }
  3509.  
  3510. void AGASeparatorPP::DrawSelf()
  3511.     {
  3512.     // Let the AGAObject draw itself.
  3513.  
  3514.     if (mAGAObject != NULL)
  3515.         mAGAObject->DrawObject();
  3516.     }
  3517.  
  3518. void AGASeparatorPP::CreateAGAObject()
  3519.     {
  3520.     // Instantiate the particular AGAObject subclass.
  3521.     
  3522.     Rect    bounds;
  3523.     
  3524.     (void) this->CalcLocalFrameRect(bounds);
  3525.  
  3526.     ThrowIfNil_(mAGAObject = new AGASeparator(&bounds));
  3527.     }
  3528.  
  3529. //
  3530. // AGACaptionPP ----------------------------------------------------
  3531. //
  3532.  
  3533. #undef Inherited
  3534. #define Inherited LCaption
  3535.  
  3536. AGACaptionPP* AGACaptionPP::CreateStream(LStream* inStream)
  3537.     {
  3538.     return new AGACaptionPP(inStream);
  3539.     }
  3540.  
  3541. AGACaptionPP::AGACaptionPP()
  3542.     {
  3543.     }
  3544.  
  3545. AGACaptionPP::AGACaptionPP(LStream* inStream)
  3546. : Inherited(inStream)
  3547.     {
  3548.     }
  3549.  
  3550. AGACaptionPP::~AGACaptionPP()
  3551.     {
  3552.     }
  3553.  
  3554. void AGACaptionPP::FinishCreateSelf()
  3555.     {
  3556.     // Need to erase when drawing, so make sure that
  3557.     // we doesn't assume we're on a gray background.
  3558.     
  3559.     (void) DetermineAGABackgroundColors(&mEnabledBackgroundColor, &mDisabledBackgroundColor, kInstallAlways);
  3560.     }
  3561.  
  3562. void AGACaptionPP::DrawSelf()
  3563.     {
  3564.     // Erase to gray before letting LCaption do its standard drawing.
  3565.     Rect    bounds;
  3566.     Boolean    enabled = this->IsEnabled();
  3567.     
  3568.     (void) this->CalcLocalFrameRect(bounds);
  3569.     
  3570.     AGADrawingEnvironment    env;
  3571.     
  3572.     {
  3573.     GDIterator    iter;
  3574.     Boolean        deep;
  3575.     
  3576.     while (iter.More(deep))
  3577.         {
  3578.         if (deep)
  3579.             {
  3580.             if (enabled)
  3581.                 ::RGBForeColor(&mEnabledBackgroundColor);
  3582.             else
  3583.                 ::RGBForeColor(&mDisabledBackgroundColor);
  3584.             }
  3585.         else
  3586.             ::RGBForeColor(&gAGARamp[rW]);
  3587.         
  3588.         ::PaintRect(&bounds);
  3589.         }
  3590.     }    // destruct the GDIterator and its clipping changes
  3591.     
  3592.     // The remaining is lifted from LCaption::DrawSelf(), except that
  3593.     // we set the text color to dimmed text color if we are not enabled.
  3594.  
  3595.     Rect    frame;
  3596.     CalcLocalFrameRect(frame);
  3597.     
  3598.     Int16    just = UTextTraits::SetPortTextTraits(mTxtrID);
  3599.     
  3600.     RGBColor    textColor;
  3601.     ::GetForeColor(&textColor);
  3602.     
  3603.     ApplyForeAndBackColors();
  3604.  
  3605.     ::TextMode(srcOr);
  3606.  
  3607.     ::RGBForeColor(&textColor);
  3608.     
  3609.     if (! enabled)
  3610.         ::RGBForeColor(&gAGARamp[r7]);
  3611.     
  3612.     UTextDrawing::DrawWithJustification((Ptr)&mText[1], mText[0], frame, just);
  3613.  
  3614.     // For any non-deep screens, we paint a gray pattern on
  3615.     // to the text if it's dim.
  3616.     
  3617.     if (! enabled)
  3618.         {
  3619.         GDIterator    iter;
  3620.         Boolean        deep;
  3621.  
  3622.         ::PenPat(&qd.gray);
  3623.         ::PenMode(patBic);
  3624.  
  3625.         while (iter.More(deep))
  3626.             if (! deep)
  3627.                 ::PaintRect(&bounds);
  3628.         }
  3629.     }
  3630.  
  3631. void AGACaptionPP::EnableSelf()
  3632.     {
  3633.     // We need to redraw when we are enabled.
  3634.  
  3635.     this->Draw(NULL);
  3636.     }
  3637.  
  3638. void AGACaptionPP::DisableSelf()
  3639.     {
  3640.     // We need to redraw when we are disabled.
  3641.  
  3642.     this->Draw(NULL);
  3643.     }
  3644.  
  3645. //
  3646. // AGAFocusBoxPP ----------------------------------------------------
  3647. //
  3648.  
  3649. #undef Inherited
  3650. #define Inherited LFocusBox
  3651.  
  3652. AGAFocusBoxPP* AGAFocusBoxPP::CreateStream(LStream* inStream)
  3653.     {
  3654.     return new AGAFocusBoxPP(inStream);
  3655.     }
  3656.  
  3657. AGAFocusBoxPP::AGAFocusBoxPP()
  3658.     {
  3659.     mIsNotched = false;
  3660.     }
  3661.  
  3662. AGAFocusBoxPP::AGAFocusBoxPP(const LFocusBox &inOriginal)
  3663. : Inherited(inOriginal)
  3664.     {
  3665.     mIsNotched = false;
  3666.     }
  3667.  
  3668. AGAFocusBoxPP::AGAFocusBoxPP(LStream* inStream)
  3669. : Inherited(inStream)
  3670.     {
  3671.     mIsNotched = false;
  3672.     }
  3673.  
  3674. AGAFocusBoxPP::~AGAFocusBoxPP()
  3675.     {
  3676.     }
  3677.  
  3678. void AGAFocusBoxPP::DrawSelf()
  3679.     {
  3680.     // Draw the AGA-style focus frame.
  3681.  
  3682.     GDIterator    iter;
  3683.     Boolean        deep;
  3684.     Rect        bounds;
  3685.  
  3686.     RgnHandle borderRegion = ::NewRgn();
  3687.     (void) this->CalcLocalFrameRect(bounds);
  3688.     
  3689.     AGAComputeTargetBorderRegion(borderRegion, &bounds, mIsNotched);
  3690.         
  3691.     while (iter.More(deep))
  3692.         {
  3693.         if (deep)
  3694.             ::RGBForeColor(&gAGARamp[r8]);
  3695.         else
  3696.             ::RGBForeColor(&gAGARamp[rB]);
  3697.  
  3698.         PaintRgn(borderRegion);
  3699.         }
  3700.     
  3701.     ::DisposeRgn(borderRegion);
  3702.     }
  3703.  
  3704. RgnHandle AGAFocusBoxPP::GetBoxRegion(const Rect &inFrame, const Rect &inRevealed) const
  3705.     {
  3706.     RgnHandle    boxRgn = ::NewRgn();
  3707.  
  3708.     AGAComputeTargetBorderRegion(boxRgn, &inFrame, mIsNotched);
  3709.     
  3710.     // Clip to revealed rect
  3711.     RgnHandle    revealedRgn = ::NewRgn();
  3712.     ::RectRgn(revealedRgn, &inRevealed);
  3713.     ::SectRgn(boxRgn, revealedRgn, boxRgn);
  3714.     ::DisposeRgn(revealedRgn);
  3715.     
  3716.     return boxRgn;
  3717.     }
  3718.  
  3719. //
  3720. // AGANotchedFocusBoxPP ----------------------------------------------------
  3721. //
  3722.  
  3723. #undef Inherited
  3724. #define Inherited AGAFocusBoxPP
  3725.  
  3726. AGANotchedFocusBoxPP* AGANotchedFocusBoxPP::CreateStream(LStream* inStream)
  3727.     {
  3728.     return new AGANotchedFocusBoxPP(inStream);
  3729.     }
  3730.  
  3731. AGANotchedFocusBoxPP::AGANotchedFocusBoxPP()
  3732.     {
  3733.     mIsNotched = true;
  3734.     }
  3735.  
  3736. AGANotchedFocusBoxPP::AGANotchedFocusBoxPP(const LFocusBox &inOriginal)
  3737. : Inherited(inOriginal)
  3738.     {
  3739.     mIsNotched = true;
  3740.     }
  3741.  
  3742. AGANotchedFocusBoxPP::AGANotchedFocusBoxPP(LStream* inStream)
  3743. : Inherited(inStream)
  3744.     {
  3745.     mIsNotched = true;
  3746.     }
  3747.  
  3748. AGANotchedFocusBoxPP::~AGANotchedFocusBoxPP()
  3749.     {
  3750.     }
  3751.  
  3752. //
  3753. // AGAListBoxPP ----------------------------------------------------
  3754. //
  3755.  
  3756. #undef Inherited
  3757. #define Inherited LListBox
  3758.  
  3759. AGAListBoxPP* AGAListBoxPP::CreateStream(LStream* inStream)
  3760.     {
  3761.     return new AGAListBoxPP(inStream);
  3762.     }
  3763.  
  3764. AGAListBoxPP::AGAListBoxPP()
  3765.     {
  3766.     mNotchedFrame = false;
  3767.     mNotchedFocusBox = false;
  3768.     }
  3769.  
  3770. AGAListBoxPP::AGAListBoxPP(LStream* inStream)
  3771. : Inherited(inStream)
  3772.     {
  3773.     mNotchedFrame = false;
  3774.     mNotchedFocusBox = false;
  3775.     }
  3776.  
  3777. AGAListBoxPP::~AGAListBoxPP()
  3778.     {
  3779.     }
  3780.  
  3781. void AGAListBoxPP::FinishCreateSelf()
  3782.     {
  3783.     // Replace the standard LFocusBox with an AGAFocusBoxPP
  3784.     // initialized from the existing one.
  3785.     
  3786.     if (mFocusBox != NULL)
  3787.         {
  3788.         AGAFocusBoxPP*    newFocusBox;
  3789.         
  3790.         if (mNotchedFocusBox)
  3791.             newFocusBox = new AGANotchedFocusBoxPP(*mFocusBox);
  3792.         else
  3793.             newFocusBox = new AGAFocusBoxPP(*mFocusBox);
  3794.         
  3795.         delete mFocusBox;
  3796.         
  3797.         mFocusBox = newFocusBox;
  3798.         mFocusBox->AttachPane(this, false);
  3799.         
  3800.         // The standard LFocusBox is smaller by 1 pixel on each
  3801.         // side than the AGA focus box, so expand ours from where
  3802.         // LFocusBox::AttachPane located and sized it.
  3803.         
  3804.         mFocusBox->MoveBy(-1, -1, true);
  3805.         mFocusBox->ResizeFrameBy(2, 2, true);
  3806.         }
  3807.  
  3808.     // Attach the white background and border frame attachments.
  3809.     
  3810.     if (mNotchedFrame)
  3811.         {
  3812.         this->AddAttachment(new AGANotchedWhiteBackgroundAttachmentPP);
  3813.         this->AddAttachment(new AGANotchedBorderFrameAttachmentPP);
  3814.         }
  3815.     else
  3816.         {
  3817.         this->AddAttachment(new AGAWhiteBackgroundAttachmentPP);
  3818.         this->AddAttachment(new AGABorderFrameAttachmentPP);
  3819.         }
  3820.     }
  3821.  
  3822. void AGAListBoxPP::DrawSelf()
  3823.     {
  3824.     this->DrawEverything(kUseUpdateRgn);
  3825.     }
  3826.  
  3827. void AGAListBoxPP::ActivateSelf()
  3828.     {
  3829.     Inherited::ActivateSelf();
  3830.     
  3831.     Rect    frame;
  3832.     (void) this->CalcLocalFrameRect(frame);
  3833.  
  3834.     if (this->ExecuteAttachments(msg_DrawOrPrint, &frame))
  3835.         this->DrawEverything(kDontUseUpdateRgn);
  3836.     }
  3837.  
  3838. void AGAListBoxPP::DeactivateSelf()
  3839.     {
  3840.     Inherited::DeactivateSelf();
  3841.  
  3842.     Rect    frame;
  3843.     (void) this->CalcLocalFrameRect(frame);
  3844.  
  3845.     if (this->ExecuteAttachments(msg_DrawOrPrint, &frame))
  3846.         this->DrawEverything(kDontUseUpdateRgn);
  3847.     }
  3848.  
  3849. void AGAListBoxPP::EnableSelf()
  3850.     {
  3851.     Rect    frame;
  3852.     (void) this->CalcLocalFrameRect(frame);
  3853.  
  3854.     if (this->IsVisible())
  3855.         if (this->ExecuteAttachments(msg_DrawOrPrint, &frame))
  3856.             this->DrawEverything(kDontUseUpdateRgn);
  3857.     }
  3858.  
  3859. void AGAListBoxPP::DisableSelf()
  3860.     {
  3861.     Rect    frame;
  3862.     (void) this->CalcLocalFrameRect(frame);
  3863.  
  3864.     if (this->IsVisible())
  3865.         if (this->ExecuteAttachments(msg_DrawOrPrint, &frame))
  3866.             this->DrawEverything(kDontUseUpdateRgn);
  3867.     }
  3868.  
  3869. void AGAListBoxPP::DrawEverything(Boolean useUpdateRgn)
  3870.     {
  3871.     // AGAListBoxPP just isn't set up to handle our situations where dimming
  3872.     // and background color changes affect the whole view. It tries to
  3873.     // optimize by not calling LUpdate upon enable/disable messages. But
  3874.     // our background may change or get painted when that happens. So we catch
  3875.     // the DrawSelf and other appropriate messages, and just draw it all.
  3876.     
  3877.     this->FocusDraw();
  3878.  
  3879.     Rect        r;
  3880.     Boolean        enabled = (mEnabled == triState_On);
  3881.     
  3882.     (void) this->CalcLocalFrameRect(r);
  3883.     
  3884.     ::PenNormal();                    // pen size 1,1, solid black pattern, srcOr
  3885.     ::RGBBackColor(&gAGARamp[rW]);
  3886.     
  3887.     if (enabled)
  3888.         ::RGBForeColor(&gAGARamp[rB]);
  3889.     else
  3890.         ::RGBForeColor(&gAGARamp[r7]);
  3891.  
  3892.     GrafPtr    savePort = (**mMacListH).port;
  3893.     (**mMacListH).port = UQDGlobals::GetCurrentPort();
  3894.     
  3895.     RgnHandle    updateRgn;
  3896.     
  3897.     if (useUpdateRgn)
  3898.         updateRgn = GetLocalUpdateRgn();
  3899.     else
  3900.         {
  3901.         updateRgn = ::NewRgn();
  3902.         ::RectRgn(updateRgn, &r);
  3903.         }
  3904.  
  3905.     ::LUpdate(updateRgn, mMacListH);
  3906.     ::DisposeRgn(updateRgn);
  3907.     
  3908.     (**mMacListH).port = savePort;
  3909.     
  3910.     // For any non-deep screens, we paint a gray pattern on
  3911.     // to the text if it's dim. Check the existence of scroll
  3912.     // bars to determine exactly where we should paint.
  3913.  
  3914.     if (! enabled)
  3915.         {
  3916.         GDIterator    iter;
  3917.         Boolean        deep;
  3918.         ListHandle    ourListHandle = this->GetMacListH();
  3919.  
  3920.         ::InsetRect(&r, 1, 1);
  3921.         
  3922.         if ((**ourListHandle).hScroll != NULL)
  3923.             r.bottom -= 15;    // room for h scroll bar
  3924.  
  3925.         if ((**ourListHandle).vScroll != NULL)
  3926.             r.right -= 15;    // room for v scroll bar
  3927.  
  3928.         ::PenPat(&qd.gray);
  3929.         ::PenMode(patBic);
  3930.  
  3931.         while (iter.More(deep))
  3932.             if (! deep)
  3933.                 ::PaintRect(&r);
  3934.         }
  3935.     }
  3936.  
  3937. //
  3938. // AGANotchedListBoxPP ----------------------------------------------------
  3939. //
  3940.  
  3941. #undef Inherited
  3942. #define Inherited AGAListBoxPP
  3943.  
  3944. AGANotchedListBoxPP* AGANotchedListBoxPP::CreateStream(LStream* inStream)
  3945.     {
  3946.     return new AGANotchedListBoxPP(inStream);
  3947.     }
  3948.  
  3949. AGANotchedListBoxPP::AGANotchedListBoxPP()
  3950.     {
  3951.     mNotchedFrame = true;
  3952.     }
  3953.  
  3954. AGANotchedListBoxPP::AGANotchedListBoxPP(LStream* inStream)
  3955. : Inherited(inStream)
  3956.     {
  3957.     mNotchedFrame = true;
  3958.     }
  3959.  
  3960. AGANotchedListBoxPP::~AGANotchedListBoxPP()
  3961.     {
  3962.     }
  3963.  
  3964. //
  3965. // AGANotchedFocusListBoxPP ----------------------------------------------------
  3966. //
  3967.  
  3968. #undef Inherited
  3969. #define Inherited AGANotchedListBoxPP
  3970.  
  3971. AGANotchedFocusListBoxPP* AGANotchedFocusListBoxPP::CreateStream(LStream* inStream)
  3972.     {
  3973.     return new AGANotchedFocusListBoxPP(inStream);
  3974.     }
  3975.  
  3976. AGANotchedFocusListBoxPP::AGANotchedFocusListBoxPP()
  3977.     {
  3978.     mNotchedFocusBox = true;
  3979.     }
  3980.  
  3981. AGANotchedFocusListBoxPP::AGANotchedFocusListBoxPP(LStream* inStream)
  3982. : Inherited(inStream)
  3983.     {
  3984.     mNotchedFocusBox = true;
  3985.     }
  3986.  
  3987. AGANotchedFocusListBoxPP::~AGANotchedFocusListBoxPP()
  3988.     {
  3989.     }
  3990.  
  3991. //
  3992. // AGAPanelEnclosurePP ----------------------------------------------------
  3993. //
  3994.  
  3995. #undef Inherited
  3996.  
  3997. AGAPanelEnclosurePP* AGAPanelEnclosurePP::CreateStream(LStream* inStream)
  3998.     {
  3999.     return new AGAPanelEnclosurePP(inStream);
  4000.     }
  4001.  
  4002. AGAPanelEnclosurePP::AGAPanelEnclosurePP(LStream* inStream)
  4003. : LView(inStream)
  4004.     {
  4005.     }
  4006.  
  4007. AGAPanelEnclosurePP::AGAPanelEnclosurePP()
  4008.     {
  4009.     }
  4010.  
  4011. AGAPanelEnclosurePP::~AGAPanelEnclosurePP()
  4012.     {
  4013.     }
  4014.  
  4015. void AGAPanelEnclosurePP::SwitchPanelOut()
  4016.     {
  4017.     if (this->IsOnDuty())
  4018.         this->SwitchTarget(NULL);
  4019.     }
  4020.  
  4021. void AGAPanelEnclosurePP::SwitchPanelIn()
  4022.     {
  4023.     if (this->GetLatentSub() != NULL)
  4024.         this->RestoreTarget();
  4025.     }
  4026.  
  4027. //
  4028. // AGATabPanelPP ----------------------------------------------------
  4029. //
  4030.  
  4031. #undef Inherited
  4032. #define Inherited LView
  4033.  
  4034. AGATabPanelPP* AGATabPanelPP::CreateStream(LStream* inStream)
  4035.     {
  4036.     return new AGATabPanelPP(inStream);
  4037.     }
  4038.  
  4039. AGATabPanelPP::AGATabPanelPP(LStream* inStream)
  4040. : Inherited(inStream)
  4041.     {
  4042.     mAGAObject = NULL;
  4043.     mLabelsTextTraitsID = 0;        // System font is std for large; Geneva 10 bold is std for small
  4044.     mLabelsResourceID = mUserCon;    // STR# resource ID of the slider labels (0 for none)
  4045.     mPanelContainerView = NULL;
  4046.     mActivePanelView = NULL;
  4047.     mTempSupressDisable = false;
  4048.     }
  4049.  
  4050. AGATabPanelPP::AGATabPanelPP()
  4051.     {
  4052.     mAGAObject = NULL;
  4053.     mLabelsTextTraitsID = 0;        // System font is std for large; Geneva 10 bold is std for small
  4054.     mLabelsResourceID = 0;            // STR# resource ID of the slider labels (0 for none)
  4055.     mPanelContainerView = NULL;
  4056.     mActivePanelView = NULL;
  4057.     mTempSupressDisable = false;
  4058.     }
  4059.  
  4060. AGATabPanelPP::~AGATabPanelPP()
  4061.     {
  4062.     // Delete AGA object if we successfully allocated it.
  4063.     // We also need to make sure that all panel views not currently
  4064.     // installed get destructed. Unfortunately, it seems that
  4065.     // the LStdControl-based classes try to Focus during destruction,
  4066.     // and don't check to see if they're in a port; this causes
  4067.     // FocusDraw to throw an exception. So it's easiest if we just
  4068.     // suck all the panels into our container and let them get deleted
  4069.     // by LView::DeleteAllSubPanes, which is called by our parent class
  4070.     // destructor.
  4071.  
  4072.     if (mAGAObject != NULL)
  4073.         {
  4074. /*
  4075.         SInt32    numTabs;
  4076.  
  4077.         numTabs = mAGAObject->GetNumTabs();
  4078.         
  4079.         for (SInt32 tabIndex = 0; tabIndex < numTabs; tabIndex++)
  4080.             {
  4081.             if (tabIndex != mAGAObject->GetCurrentTab())
  4082.                 this->SwitchPanelIn(tabIndex, false);    // make it part of the hierarchy for deletion
  4083.             }
  4084. */
  4085.         delete mAGAObject;
  4086.         }
  4087.     }
  4088.  
  4089. void AGATabPanelPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
  4090.     {
  4091.     // Let the PowerPlant and AGA objects update their bounds.
  4092.  
  4093.     Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  4094.     
  4095.     ResetAGAObjectFrame(this, mAGAObject);
  4096.     }
  4097.  
  4098. void AGATabPanelPP::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
  4099.     {
  4100.     // Let the PowerPlant and AGA objects update their bounds.
  4101.  
  4102.     Inherited::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  4103.     
  4104.     ResetAGAObjectFrame(this, mAGAObject);
  4105.     }
  4106.  
  4107. void AGATabPanelPP::FinishCreateSelf()
  4108.     {
  4109.     // Create and set up the AGAObject.
  4110.  
  4111.     this->CreateAGAObject();
  4112.     
  4113.     // Create the container view that we'll load panels in and out of.
  4114.     
  4115.     this->CreateContainerView();
  4116.     }
  4117.  
  4118. void AGATabPanelPP::DrawSelf()
  4119.     {
  4120.     // Let the AGAObject draw itself.
  4121.  
  4122.     if (mAGAObject != NULL)
  4123.         mAGAObject->DrawObject();
  4124.     }
  4125.  
  4126. void AGATabPanelPP::ClickSelf(const SMouseDownEvent &inMouseDown)
  4127.     {
  4128.     // Let the AGAObject track the mouse.
  4129.  
  4130.     if (mAGAObject != NULL)
  4131.         {
  4132.         this->FocusDraw();
  4133.         
  4134.         if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
  4135.             this->HandleTabSwitch(mAGAObject->GetLastTabClicked());
  4136.         }
  4137.     }
  4138.  
  4139. void AGATabPanelPP::EnableSelf()
  4140.     {
  4141.     // Let the AGAObject enable itself.
  4142.  
  4143.     if (mAGAObject != NULL)
  4144.         {
  4145.         this->FocusDraw();
  4146.         mAGAObject->SetEnable(AGAObject::kEnabled, this->IsVisible());
  4147.         }
  4148.     }
  4149.  
  4150. void AGATabPanelPP::DisableSelf()
  4151.     {
  4152.     // Let the AGAObject disable itself.
  4153.  
  4154.     if ((mAGAObject != NULL) && ! mTempSupressDisable)
  4155.         {
  4156.         this->FocusDraw();
  4157.         mAGAObject->SetEnable(AGAObject::kDisabled, this->IsVisible());
  4158.         }
  4159.     }
  4160.  
  4161. void AGATabPanelPP::CreateAGAObject()
  4162.     {
  4163.     // Instantiate the particular AGAObject subclass.
  4164.  
  4165.     Rect    bounds;
  4166.     
  4167.     (void) this->CalcLocalFrameRect(bounds);
  4168.  
  4169.     ThrowIfNil_(mAGAObject = new AGATabPanel(&bounds, 0, AGATextStyle(mLabelsTextTraitsID), mLabelsResourceID));
  4170.  
  4171.     // Tab panel has to erase when drawing, so make sure that
  4172.     // it doesn't assume we're on a gray background.
  4173.  
  4174.     this->FocusDraw();
  4175.     this->ApplyForeAndBackColors();
  4176.     InstallAGABackgroundColors(mAGAObject, kInstallAlways);
  4177.     }
  4178.  
  4179. void AGATabPanelPP::CreateContainerView()
  4180.     {
  4181.     if (mAGAObject->HasFrame())    // if no frame, we just run the tabs, not the panels
  4182.         {
  4183.         // Create a subview to contain the panels that we load and unload.
  4184.         
  4185.         LPane::SetDefaultView(this);
  4186.  
  4187.         SInt16        tabHeight = mAGAObject->GetTabHeight();
  4188.         SPaneInfo    paneInfo;
  4189.         SViewInfo    viewInfo;
  4190.         
  4191.         // Init the paneInfo with our own coordinates & bindings.
  4192.         paneInfo.paneID = 0;
  4193.         paneInfo.width = mFrameSize.width;
  4194.         paneInfo.height = mFrameSize.height;
  4195.         paneInfo.visible = true;
  4196.         paneInfo.enabled = true;
  4197.         paneInfo.bindings = mFrameBinding;
  4198.         paneInfo.left = mFrameLocation.h;
  4199.         paneInfo.top = mFrameLocation.v;
  4200.         paneInfo.userCon = 0;
  4201.         paneInfo.superView = mSuperView;
  4202.         
  4203.         // Inset the bounds by 4 pixels, plus the tab height at the top.
  4204.         paneInfo.top += (tabHeight + 4);
  4205.         paneInfo.left += 4;
  4206.         paneInfo.height -= (tabHeight + 8);
  4207.         paneInfo.width -= 8;
  4208.         
  4209.         // Init the viewInfo with the pane's dimensions.
  4210.         viewInfo.imageSize.width = paneInfo.width;
  4211.         viewInfo.imageSize.height = paneInfo.height;
  4212.         viewInfo.scrollPos.h = 0;
  4213.         viewInfo.scrollPos.v = 0;
  4214.         viewInfo.scrollUnit.h = 0;
  4215.         viewInfo.scrollUnit.v = 0;
  4216.         viewInfo.reconcileOverhang = 0;
  4217.  
  4218.         // Create the view and make it a subview of ourself.
  4219.         mPanelContainerView = new LView(paneInfo, viewInfo);
  4220.         mPanelContainerView->FinishCreate();
  4221.         mPanelContainerView->PutInside(this, true);
  4222.         }
  4223.     }
  4224.  
  4225. void AGATabPanelPP::SetValue(SInt32 inValue)
  4226.     {
  4227.     // Switch to the specified tab index.
  4228.     
  4229.     this->SwitchPanels(inValue);
  4230.     }
  4231.  
  4232. SInt32 AGATabPanelPP::GetValue() const
  4233.     {
  4234.     // Return the index of the currently selected tab.
  4235.  
  4236.     if (mAGAObject == NULL)
  4237.         return 0;
  4238.     else
  4239.         return mAGAObject->GetCurrentTab();
  4240.     }
  4241.     
  4242. void AGATabPanelPP::Disable()
  4243.     {
  4244.     // Need to change the way disable works because of the sequence of
  4245.     // drawing that normally occurs for a view with subpanes. The normal
  4246.     // sequence draws the parent view (us) after drawing the subpanes,
  4247.     // which is wrong because our disable drawing has to paint the whole
  4248.     // pane gray, which covers all subpanes. So instead we get ourself
  4249.     // to draw disabled first, then let the normal stuff occur while
  4250.     // setting a flag that tells us to skip the draw disabled message
  4251.     // that we'll get during that processing. Kinda ugly, but it works.
  4252.     
  4253.     if (this->IsEnabled())
  4254.         this->DisableSelf();
  4255.  
  4256.     mTempSupressDisable = true;
  4257.     Inherited::Disable();
  4258.     mTempSupressDisable = false;
  4259.     }
  4260.  
  4261. void AGATabPanelPP::SwitchPanels(SInt32 newTabIndex)
  4262.     {
  4263.     // Switch to the specified tab index.
  4264.     
  4265.     if (mAGAObject != NULL)
  4266.         {
  4267.         this->FocusDraw();
  4268.         
  4269.         mAGAObject->SetCurrentTab(newTabIndex, this->IsVisible());
  4270.         }
  4271.  
  4272.     this->SwitchPanelOut();
  4273.     this->SwitchPanelIn(newTabIndex);
  4274.     }
  4275.  
  4276. void AGATabPanelPP::HandleTabSwitch(SInt32 newTabIndex)
  4277.     {
  4278.     // If it's OK to switch tabs (may need to validate current
  4279.     // panel before switching), do the switch.
  4280.  
  4281.     if (this->ValidatePanel(mAGAObject->GetCurrentTab()))
  4282.         this->SetValue(newTabIndex);
  4283.     }
  4284.  
  4285. void AGATabPanelPP::AddPanel(ResIDT panelResourceID, StringPtr tabLabel)
  4286.     {
  4287.     // Create a new tab and assign the specified panel to it.
  4288.  
  4289.     if (mAGAObject != NULL)
  4290.         {
  4291.         Str255    actualTabLabel;
  4292.         SInt32    numTabs;
  4293.  
  4294.         if (tabLabel != NULL)
  4295.             AGA_PLstrcpy(actualTabLabel, tabLabel);
  4296.         else
  4297.             {
  4298.             Handle    ppobHandle;
  4299.             SInt16    ppobID;
  4300.             OSType    ppobType;
  4301.             
  4302.             ThrowIfNil_(ppobHandle = ::GetResource('PPob', panelResourceID));
  4303.             
  4304.             ::GetResInfo(ppobHandle, &ppobID, &ppobType, actualTabLabel);
  4305.             
  4306.             // Don't release it -- we're about to cause it to be read anyway.
  4307.             }
  4308.  
  4309.         numTabs = mAGAObject->GetNumTabs();
  4310.         
  4311.         mAGAObject->SetNumTabs(numTabs + 1, AGATabPanel::kDontShrink);
  4312.         
  4313.         this->InstallPanel(numTabs, panelResourceID, actualTabLabel);
  4314.         }
  4315.     }
  4316.  
  4317. void AGATabPanelPP::InstallPanel(SInt32 tabIndex, ResIDT panelResourceID, StringPtr tabLabel)
  4318.     {
  4319.     // Assign the specified panel to the specified tab.
  4320.  
  4321.     if (mAGAObject != NULL)
  4322.         {
  4323.         LView*    newPanelView;
  4324.         SInt32    numTabs;
  4325.  
  4326.         numTabs = mAGAObject->GetNumTabs();
  4327.         
  4328.         if (tabIndex < numTabs)
  4329.             {
  4330.             // To keep the command chain in an orderly state, we need to create the
  4331.             // panel view as a subcommander of another commander. In the MacApp world,
  4332.             // this would just be its superview. But in PowerPlant, LPane is not a
  4333.             // commander; only certain pane classes mix in LCommander. So we have to
  4334.             // walk up the superview chain until we find an LCommander subclass object,
  4335.             // via dynamic casting.
  4336.             //
  4337.             // If you bypass the RTTI here, you must ensure that the tab panel view
  4338.             // lives in a view hierarchy with an LCommander (such as LWindow or LDialogBox)
  4339.             // at the root.
  4340.             
  4341.             LCommander*    nearestSuperCommander = NULL;
  4342.             LView*        aSuperView = mPanelContainerView;
  4343.             
  4344.             while ((nearestSuperCommander == NULL) && (aSuperView != NULL))
  4345.                 {
  4346. #ifndef NO_RTTI
  4347.  
  4348.                 // Found if this superview is an LCommander.
  4349.                 nearestSuperCommander = dynamic_cast<LCommander*>(aSuperView);
  4350.  
  4351. #else // NO_RTTI
  4352.  
  4353.                 // Found if this superview is the root view (window or dialog).
  4354.                 if (aSuperView->GetSuperView() == NULL)
  4355.                     nearestSuperCommander = (LCommander*) aSuperView;
  4356.  
  4357. #endif // NO_RTTI
  4358.  
  4359.                 aSuperView = aSuperView->GetSuperView();
  4360.                 }
  4361.             
  4362.             // Wrap the CreateView with custom color values so that the
  4363.             // AGA objects in the panel hierarchy will get the right background
  4364.             // colors.
  4365.  
  4366.             TurnOnCustomAGABackgroundColors(&gAGARamp[r1], &gAGARamp[r2]);
  4367.             ThrowIfNil_(newPanelView = UReanimator::CreateView(panelResourceID, mPanelContainerView, nearestSuperCommander));
  4368.             TurnOffCustomAGABackgroundColors();
  4369.  
  4370.             newPanelView->Hide();
  4371.             
  4372.             mAGAObject->SetTabUserData(tabIndex, newPanelView);
  4373.             
  4374.             if (tabLabel != NULL)
  4375.                 {
  4376.                 mAGAObject->SetTabLabel(tabIndex, tabLabel);
  4377.                 mAGAObject->CalculateTabWidths();
  4378.                 }
  4379.  
  4380.             // If this panel corresponds to the initial value, switch it in.
  4381.  
  4382.             if (this->GetValue() == tabIndex)
  4383.                 this->SwitchPanels(tabIndex);
  4384.             }
  4385.         }
  4386.     }
  4387.  
  4388. LView* AGATabPanelPP::GetPanelView(SInt32 tabIndex)
  4389.     {
  4390.     // Return the top LView* of the specified tab's panel view hierarchy.
  4391.  
  4392.     if (mAGAObject == NULL)
  4393.         return NULL;
  4394.     else
  4395.         return (LView*) mAGAObject->GetTabUserData(tabIndex);
  4396.     }
  4397.  
  4398. Boolean AGATabPanelPP::ValidatePanel(SInt32 /*currentTabIndex*/)
  4399.     {
  4400.     // (Override for app-specific validation.)
  4401.     //
  4402.     // Return true if the current (specified) panel is valid and
  4403.     // it's OK to switch to a different panel. Return false otherwise
  4404.     // and the tab switch will not occur; it's OK to alert the user
  4405.     // of the invalid data before returning false.
  4406.     //
  4407.  
  4408.     return true;
  4409.     }
  4410.  
  4411. void AGATabPanelPP::SwitchPanelOut()
  4412.     {
  4413.     // Make the current panel invisible and disabled.
  4414.  
  4415.     if (mActivePanelView != NULL)
  4416.         {
  4417. #ifndef NO_RTTI
  4418.  
  4419.         // If the current panel root is an AGAPanelEnclosurePP,
  4420.         // we can give it a chance to clean up its target.
  4421.         // If you bypass the RTTI here, the current panel may not
  4422.         // give up the target.
  4423.         
  4424.         AGAPanelEnclosurePP*    enclosure = dynamic_cast<AGAPanelEnclosurePP*>(mActivePanelView);
  4425.  
  4426.         if (enclosure != NULL)
  4427.             enclosure->SwitchPanelOut();
  4428.  
  4429. #endif // NO_RTTI
  4430.  
  4431.         mActivePanelView->Hide();
  4432.         mActivePanelView->Disable();
  4433.         mActivePanelView = NULL;
  4434.         }
  4435.     }
  4436.  
  4437. void AGATabPanelPP::SwitchPanelIn(SInt32 newTabIndex)
  4438.     {
  4439.     // Make the specified tab's panel visible and enabled.
  4440.  
  4441.     if (mAGAObject != NULL)
  4442.         {
  4443.         LView*    newPanelView = (LView*) mAGAObject->GetTabUserData(newTabIndex);
  4444.         
  4445.         if (newPanelView != NULL)
  4446.             {
  4447.             mActivePanelView = newPanelView;
  4448.  
  4449.             newPanelView->Enable();
  4450.             newPanelView->Show();
  4451.             
  4452.             // If the current panel root is an AGAPanelEnclosurePP,
  4453.             // we can give it a chance to restore its target.
  4454.             // If you bypass the RTTI here, the new panel may not
  4455.             // grab the target.
  4456.             
  4457. #ifndef NO_RTTI
  4458.  
  4459.             AGAPanelEnclosurePP*    enclosure = dynamic_cast<AGAPanelEnclosurePP*>(newPanelView);
  4460.  
  4461.             if (enclosure != NULL)
  4462.                 enclosure->SwitchPanelIn();
  4463.  
  4464. #endif // NO_RTTI
  4465.             }
  4466.         }
  4467.     }
  4468.  
  4469. //
  4470. // AGATabPanelPPX ----------------------------------------------------
  4471. //
  4472.  
  4473. #undef Inherited
  4474. #define Inherited AGATabPanelPP
  4475.  
  4476. AGATabPanelPPX* AGATabPanelPPX::CreateStream(LStream* inStream)
  4477.     {
  4478.     return new AGATabPanelPPX(inStream);
  4479.     }
  4480.  
  4481. AGATabPanelPPX::AGATabPanelPPX(LStream* inStream)
  4482. : Inherited(inStream)
  4483.     {
  4484.     // Read the labels STR# ID and labels text traits ID from the stream.
  4485.  
  4486.     inStream->ReadData(&mLabelsResourceID, sizeof(mLabelsResourceID));
  4487.     inStream->ReadData(&mLabelsTextTraitsID, sizeof(mLabelsTextTraitsID));
  4488.     }
  4489.  
  4490. AGATabPanelPPX::~AGATabPanelPPX()
  4491.     {
  4492.     }
  4493.  
  4494. //
  4495. // AGASmallTabPanelPP ----------------------------------------------------
  4496. //
  4497.  
  4498. #undef Inherited
  4499. #define Inherited AGATabPanelPP
  4500.  
  4501. AGASmallTabPanelPP* AGASmallTabPanelPP::CreateStream(LStream* inStream)
  4502.     {
  4503.     return new AGASmallTabPanelPP(inStream);
  4504.     }
  4505.  
  4506. AGASmallTabPanelPP::AGASmallTabPanelPP(LStream* inStream)
  4507. : Inherited(inStream)
  4508.     {
  4509.     }
  4510.  
  4511. AGASmallTabPanelPP::~AGASmallTabPanelPP()
  4512.     {
  4513.     }
  4514.  
  4515. void AGASmallTabPanelPP::CreateAGAObject()
  4516.     {
  4517.     Inherited::CreateAGAObject();
  4518.     
  4519.     // Set the tabs to use the standard small appearance.
  4520.  
  4521.     mAGAObject->SetTabSize(AGATabPanel::kSmallTabs);
  4522.     mAGAObject->SetLabelsStyle(gAGAStdBoldSmallStyle);
  4523.     }
  4524.  
  4525.